Skip to content

Commit

Permalink
Initial release (#48)
Browse files Browse the repository at this point in the history
Co-authored-by: Keith Smiley <keithbsmiley@gmail.com>
Co-authored-by: Jose Ulises Nino Rivera <junr03@users.noreply.github.com>
Co-authored-by: Tony Allen <tallen@lyft.com>
Co-authored-by: Michael Rebello <me@michaelrebello.com>
Co-authored-by: Alan Chiu <achiu@lyft.com>
Co-authored-by: Matt Klein <mklein@lyft.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
7 people authored and jpsim committed Nov 29, 2022
1 parent 1938516 commit 5e0c2cb
Show file tree
Hide file tree
Showing 51 changed files with 1,311 additions and 5 deletions.
19 changes: 19 additions & 0 deletions mobile/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
startup --host_jvm_args=-Xmx512m

build \
--define=google_grpc=disabled \
--define=hot_restart=disabled \
--define=signal_trace=disabled \
--define=tcmalloc=disabled \
--ios_minimum_os=10.0 \
--ios_simulator_device="iPhone X" \
--ios_simulator_version=12.2 \
--spawn_strategy=standalone \
--verbose_failures \
--workspace_status_command=envoy/bazel/get_workspace_status \
--xcode_version=10.2.1 \
--incompatible_bzl_disallow_load_after_statement=false

build:ios --define=manual_stamp=manual_stamp

build:android --fat_apk_cpu=x86,x86_64,armeabi-v7a,arm64-v8a
1 change: 1 addition & 0 deletions mobile/.clang-format
13 changes: 11 additions & 2 deletions mobile/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
build_docs/
generated/
/bazel-*
/build_*
/dist/envoy.aar
/dist/Envoy.framework
.DS_Store
/generated
.idea
.ijwb
*.pyc
tags
.vscode
53 changes: 53 additions & 0 deletions mobile/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
licenses(["notice"]) # Apache 2

load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_framework", "ios_static_framework")

envoy_package()

load("//bazel:aar_with_jni.bzl", "aar_with_jni")

ios_static_framework(
name = "ios_framework",
hdrs = ["//library/common:main_interface.h"],
bundle_name = "Envoy",
minimum_os_version = "10.0",
visibility = ["//visibility:public"],
deps = ["//library/common:envoy_main_interface_lib"],
)

genrule(
name = "ios_dist",
srcs = ["//:ios_framework"],
outs = ["ios_out"],
cmd = """
unzip -o $< -d dist/
touch $@
""",
)

aar_with_jni(
name = "android_aar",
android_library = "android_lib",
archive_name = "envoy",
visibility = ["//visibility:public"],
)

android_library(
name = "android_lib",
srcs = ["library/java/io/envoyproxy/envoymobile/Envoy.java"],
custom_package = "io.envoyproxy.envoymobile",
manifest = "library/EnvoyManifest.xml",
deps = ["//library/common:envoy_jni_interface_lib"],
)

genrule(
name = "android_dist",
srcs = ["//:android_aar"],
outs = ["android_out"],
cmd = """
cp $< dist/envoy.aar
chmod 755 dist/envoy.aar
touch $@
""",
)
48 changes: 47 additions & 1 deletion mobile/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Envoy Mobile
# Envoy Mobile

Mobile client networking libraries based on the [Envoy](https://www.envoyproxy.io/) project.

Expand Down Expand Up @@ -31,3 +31,49 @@ copyrighted by the *Envoy proxy authors* and the
[Cloud Native Computing Foundation](https://cncf.io). The Envoy name is used with permission from
the CNCF under the assumption that if this project finds traction it will be donated to the
Envoy proxy project.

## Building

### Requirements

- Xcode 10.2.1
- Bazel 0.25.3 (can't use 0.26.0 because of [this issue](https://github.com/bazelbuild/tulsi/issues/86))

### iOS

#### Build the iOS static framework:

```
bazel build ios_dist --config=ios
```

This will yield an `Envoy.framework` in the [`dist` directory](./dist).

#### Run the Swift app:

```
bazel run //examples/swift/hello_world:app --config=ios
```

#### Run the Objective-C app:

```
bazel run //examples/objective-c/hello_world:app --config=ios
```

### Android

#### Build the Android AAR:

```
bazel build android_dist --config=android
```

#### Run the Java app:

```
bazel mobile-install //examples/java/hello_world:hello_envoy --fat_apk_cpu=x86
```

If you have issues getting Envoy to compile locally, see the
[Envoy docs on building with Bazel](https://github.com/envoyproxy/envoy/tree/master/bazel).
88 changes: 88 additions & 0 deletions mobile/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# TODO remove once https://github.com/bazelbuild/rules_foreign_cc/pull/253 is resolved
# NOTE: this version should be kept up to date with https://github.com/lyft/envoy-edge-fork/blob/3573b07af1ab5c4cf687ced0f80e2ccc0a0b7ec2/bazel/repository_locations.bzl#L225-L230 until this is removed
http_archive(
name = "rules_foreign_cc",
patches = ["//bazel:ranlib.patch"],
sha256 = "e1b67e1fda647c7713baac11752573bfd4c2d45ef09afb4d4de9eb9bd4e5ac76",
strip_prefix = "rules_foreign_cc-8648b0446092ef2a34d45b02c8dc4c35c3a8df79",
urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/8648b0446092ef2a34d45b02c8dc4c35c3a8df79.tar.gz"],
)

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

local_repository(
name = "envoy",
path = "envoy",
)

local_repository(
name = "envoy_build_config",
path = "envoy_build_config",
)

git_repository(
name = "build_bazel_rules_apple",
commit = "2f20f88d85c0fe217cf9a9eadfb8015b3a384dea",
remote = "https://github.com/bazelbuild/rules_apple.git",
)

load("@envoy//bazel:api_repositories.bzl", "envoy_api_dependencies")

envoy_api_dependencies()

load("@envoy//bazel:repositories.bzl", "GO_VERSION", "envoy_dependencies")
load("@envoy//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

cc_configure()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(go_version = GO_VERSION)

git_repository(
name = "build_bazel_apple_support",
commit = "dabf718975760b4d45bd7db3e18bc12e7b4ef485",
remote = "https://github.com/bazelbuild/apple_support.git",
shallow_since = "1551297696 -0500",
)

git_repository(
name = "build_bazel_rules_swift",
commit = "e517571f92fe7739635c6e25b2be1f4f185fce33",
remote = "https://github.com/bazelbuild/rules_swift.git",
shallow_since = "1551797865 -0800",
)

load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")

apple_support_dependencies()

load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")

apple_rules_dependencies(ignore_version_differences = True)

load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies")

swift_rules_dependencies()

android_sdk_repository(name = "androidsdk")

android_ndk_repository(name = "androidndk")

git_repository(
name = "rules_jvm_external",
commit = "fc5bd21820581f342a4119a89bfdf36e79c6c549",
remote = "https://github.com/bazelbuild/rules_jvm_external.git",
shallow_since = "1552938175 -0400",
)
1 change: 1 addition & 0 deletions mobile/bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
licenses(["notice"]) # Apache 2
42 changes: 42 additions & 0 deletions mobile/bazel/aar_with_jni.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Based on https://github.com/aj-michael/aar_with_jni

def aar_with_jni(name, android_library, archive_name = "", visibility = None):
if not archive_name:
archive_name = name

native.genrule(
name = archive_name + "_binary_manifest_generator",
outs = [archive_name + "_generated_AndroidManifest.xml"],
cmd = """
cat > $(OUTS) <<EOF
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="does.not.matter">
<uses-sdk android:minSdkVersion="999"/>
</manifest>
EOF
""",
)

native.android_binary(
name = archive_name + "_jni",
manifest = archive_name + "_generated_AndroidManifest.xml",
custom_package = "does.not.matter",
deps = [android_library],
)

native.genrule(
name = name,
srcs = [android_library + ".aar", archive_name + "_jni_unsigned.apk"],
outs = [archive_name + ".aar"],
cmd = """
cp $(location {}.aar) $(location :{}.aar)
chmod +w $(location :{}.aar)
origdir=$$PWD
cd $$(mktemp -d)
unzip $$origdir/$(location :{}_jni_unsigned.apk) "lib/*"
cp -r lib jni
zip -r $$origdir/$(location :{}.aar) jni/*/*.so
""".format(android_library, archive_name, archive_name, archive_name, archive_name),
visibility = visibility,
)
10 changes: 10 additions & 0 deletions mobile/bazel/ranlib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- tools/build_defs/cmake_script.bzl
+++ tools/build_defs/cmake_script.bzl
@@ -91,6 +91,7 @@ _CMAKE_ENV_VARS_FOR_CROSSTOOL = {
_CMAKE_CACHE_ENTRIES_CROSSTOOL = {
"CMAKE_SYSTEM_NAME": struct(value = "CMAKE_SYSTEM_NAME", replace = True),
"CMAKE_AR": struct(value = "CMAKE_AR", replace = True),
+ "CMAKE_RANLIB": struct(value = "CMAKE_RANLIB", replace = True),
"CMAKE_CXX_LINK_EXECUTABLE": struct(value = "CMAKE_CXX_LINK_EXECUTABLE", replace = True),
"CMAKE_C_FLAGS": struct(value = "CMAKE_C_FLAGS_INIT", replace = False),
"CMAKE_CXX_FLAGS": struct(value = "CMAKE_CXX_FLAGS_INIT", replace = False),
23 changes: 23 additions & 0 deletions mobile/dist/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
licenses(["notice"]) # Apache 2

load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import")

envoy_package()

# NOTE: You must first build the top-level targets //:ios_dist and //:android_dist to use the
# artifacts referenced here.

aar_import(
name = "envoy_mobile_android",
aar = "envoy.aar",
)

apple_static_framework_import(
name = "envoy_mobile_ios",
framework_imports = glob(["Envoy.framework/**"]),
sdk_dylibs = [
"resolv.9",
"c++",
],
)
Loading

0 comments on commit 5e0c2cb

Please sign in to comment.