Skip to content

Commit 8e7a161

Browse files
goawaykeithjunr03Tony Allenrebello95
authored andcommitted
Initial release (#48)
Co-authored-by: Keith Smiley <[email protected]> Co-authored-by: Jose Ulises Nino Rivera <[email protected]> Co-authored-by: Tony Allen <[email protected]> Co-authored-by: Michael Rebello <[email protected]> Co-authored-by: Alan Chiu <[email protected]> Co-authored-by: Matt Klein <[email protected]> Signed-off-by: Mike Schore <[email protected]> Signed-off-by: JP Simard <[email protected]>
1 parent 3339229 commit 8e7a161

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1311
-5
lines changed

mobile/.bazelrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
startup --host_jvm_args=-Xmx512m
2+
3+
build \
4+
--define=google_grpc=disabled \
5+
--define=hot_restart=disabled \
6+
--define=signal_trace=disabled \
7+
--define=tcmalloc=disabled \
8+
--ios_minimum_os=10.0 \
9+
--ios_simulator_device="iPhone X" \
10+
--ios_simulator_version=12.2 \
11+
--spawn_strategy=standalone \
12+
--verbose_failures \
13+
--workspace_status_command=envoy/bazel/get_workspace_status \
14+
--xcode_version=10.2.1 \
15+
--incompatible_bzl_disallow_load_after_statement=false
16+
17+
build:ios --define=manual_stamp=manual_stamp
18+
19+
build:android --fat_apk_cpu=x86,x86_64,armeabi-v7a,arm64-v8a

mobile/.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
envoy/.clang-format

mobile/.gitignore

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
build_docs/
2-
generated/
1+
/bazel-*
2+
/build_*
3+
/dist/envoy.aar
4+
/dist/Envoy.framework
5+
.DS_Store
6+
/generated
7+
.idea
8+
.ijwb
9+
*.pyc
10+
tags
11+
.vscode

mobile/BUILD

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
4+
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application", "ios_framework", "ios_static_framework")
5+
6+
envoy_package()
7+
8+
load("//bazel:aar_with_jni.bzl", "aar_with_jni")
9+
10+
ios_static_framework(
11+
name = "ios_framework",
12+
hdrs = ["//library/common:main_interface.h"],
13+
bundle_name = "Envoy",
14+
minimum_os_version = "10.0",
15+
visibility = ["//visibility:public"],
16+
deps = ["//library/common:envoy_main_interface_lib"],
17+
)
18+
19+
genrule(
20+
name = "ios_dist",
21+
srcs = ["//:ios_framework"],
22+
outs = ["ios_out"],
23+
cmd = """
24+
unzip -o $< -d dist/
25+
touch $@
26+
""",
27+
)
28+
29+
aar_with_jni(
30+
name = "android_aar",
31+
android_library = "android_lib",
32+
archive_name = "envoy",
33+
visibility = ["//visibility:public"],
34+
)
35+
36+
android_library(
37+
name = "android_lib",
38+
srcs = ["library/java/io/envoyproxy/envoymobile/Envoy.java"],
39+
custom_package = "io.envoyproxy.envoymobile",
40+
manifest = "library/EnvoyManifest.xml",
41+
deps = ["//library/common:envoy_jni_interface_lib"],
42+
)
43+
44+
genrule(
45+
name = "android_dist",
46+
srcs = ["//:android_aar"],
47+
outs = ["android_out"],
48+
cmd = """
49+
cp $< dist/envoy.aar
50+
chmod 755 dist/envoy.aar
51+
touch $@
52+
""",
53+
)

mobile/README.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Envoy Mobile
1+
# Envoy Mobile
22

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

@@ -31,3 +31,49 @@ copyrighted by the *Envoy proxy authors* and the
3131
[Cloud Native Computing Foundation](https://cncf.io). The Envoy name is used with permission from
3232
the CNCF under the assumption that if this project finds traction it will be donated to the
3333
Envoy proxy project.
34+
35+
## Building
36+
37+
### Requirements
38+
39+
- Xcode 10.2.1
40+
- Bazel 0.25.3 (can't use 0.26.0 because of [this issue](https://github.com/bazelbuild/tulsi/issues/86))
41+
42+
### iOS
43+
44+
#### Build the iOS static framework:
45+
46+
```
47+
bazel build ios_dist --config=ios
48+
```
49+
50+
This will yield an `Envoy.framework` in the [`dist` directory](./dist).
51+
52+
#### Run the Swift app:
53+
54+
```
55+
bazel run //examples/swift/hello_world:app --config=ios
56+
```
57+
58+
#### Run the Objective-C app:
59+
60+
```
61+
bazel run //examples/objective-c/hello_world:app --config=ios
62+
```
63+
64+
### Android
65+
66+
#### Build the Android AAR:
67+
68+
```
69+
bazel build android_dist --config=android
70+
```
71+
72+
#### Run the Java app:
73+
74+
```
75+
bazel mobile-install //examples/java/hello_world:hello_envoy --fat_apk_cpu=x86
76+
```
77+
78+
If you have issues getting Envoy to compile locally, see the
79+
[Envoy docs on building with Bazel](https://github.com/envoyproxy/envoy/tree/master/bazel).

mobile/WORKSPACE

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
4+
# TODO remove once https://github.com/bazelbuild/rules_foreign_cc/pull/253 is resolved
5+
# 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
6+
http_archive(
7+
name = "rules_foreign_cc",
8+
patches = ["//bazel:ranlib.patch"],
9+
sha256 = "e1b67e1fda647c7713baac11752573bfd4c2d45ef09afb4d4de9eb9bd4e5ac76",
10+
strip_prefix = "rules_foreign_cc-8648b0446092ef2a34d45b02c8dc4c35c3a8df79",
11+
urls = ["https://github.com/bazelbuild/rules_foreign_cc/archive/8648b0446092ef2a34d45b02c8dc4c35c3a8df79.tar.gz"],
12+
)
13+
14+
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
15+
16+
local_repository(
17+
name = "envoy",
18+
path = "envoy",
19+
)
20+
21+
local_repository(
22+
name = "envoy_build_config",
23+
path = "envoy_build_config",
24+
)
25+
26+
git_repository(
27+
name = "build_bazel_rules_apple",
28+
commit = "2f20f88d85c0fe217cf9a9eadfb8015b3a384dea",
29+
remote = "https://github.com/bazelbuild/rules_apple.git",
30+
)
31+
32+
load("@envoy//bazel:api_repositories.bzl", "envoy_api_dependencies")
33+
34+
envoy_api_dependencies()
35+
36+
load("@envoy//bazel:repositories.bzl", "GO_VERSION", "envoy_dependencies")
37+
load("@envoy//bazel:cc_configure.bzl", "cc_configure")
38+
39+
envoy_dependencies()
40+
41+
load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")
42+
43+
rules_foreign_cc_dependencies()
44+
45+
cc_configure()
46+
47+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
48+
49+
go_rules_dependencies()
50+
51+
go_register_toolchains(go_version = GO_VERSION)
52+
53+
git_repository(
54+
name = "build_bazel_apple_support",
55+
commit = "dabf718975760b4d45bd7db3e18bc12e7b4ef485",
56+
remote = "https://github.com/bazelbuild/apple_support.git",
57+
shallow_since = "1551297696 -0500",
58+
)
59+
60+
git_repository(
61+
name = "build_bazel_rules_swift",
62+
commit = "e517571f92fe7739635c6e25b2be1f4f185fce33",
63+
remote = "https://github.com/bazelbuild/rules_swift.git",
64+
shallow_since = "1551797865 -0800",
65+
)
66+
67+
load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")
68+
69+
apple_support_dependencies()
70+
71+
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
72+
73+
apple_rules_dependencies(ignore_version_differences = True)
74+
75+
load("@build_bazel_rules_swift//swift:repositories.bzl", "swift_rules_dependencies")
76+
77+
swift_rules_dependencies()
78+
79+
android_sdk_repository(name = "androidsdk")
80+
81+
android_ndk_repository(name = "androidndk")
82+
83+
git_repository(
84+
name = "rules_jvm_external",
85+
commit = "fc5bd21820581f342a4119a89bfdf36e79c6c549",
86+
remote = "https://github.com/bazelbuild/rules_jvm_external.git",
87+
shallow_since = "1552938175 -0400",
88+
)

mobile/bazel/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
licenses(["notice"]) # Apache 2

mobile/bazel/aar_with_jni.bzl

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Based on https://github.com/aj-michael/aar_with_jni
2+
3+
def aar_with_jni(name, android_library, archive_name = "", visibility = None):
4+
if not archive_name:
5+
archive_name = name
6+
7+
native.genrule(
8+
name = archive_name + "_binary_manifest_generator",
9+
outs = [archive_name + "_generated_AndroidManifest.xml"],
10+
cmd = """
11+
cat > $(OUTS) <<EOF
12+
<manifest
13+
xmlns:android="http://schemas.android.com/apk/res/android"
14+
package="does.not.matter">
15+
<uses-sdk android:minSdkVersion="999"/>
16+
</manifest>
17+
EOF
18+
""",
19+
)
20+
21+
native.android_binary(
22+
name = archive_name + "_jni",
23+
manifest = archive_name + "_generated_AndroidManifest.xml",
24+
custom_package = "does.not.matter",
25+
deps = [android_library],
26+
)
27+
28+
native.genrule(
29+
name = name,
30+
srcs = [android_library + ".aar", archive_name + "_jni_unsigned.apk"],
31+
outs = [archive_name + ".aar"],
32+
cmd = """
33+
cp $(location {}.aar) $(location :{}.aar)
34+
chmod +w $(location :{}.aar)
35+
origdir=$$PWD
36+
cd $$(mktemp -d)
37+
unzip $$origdir/$(location :{}_jni_unsigned.apk) "lib/*"
38+
cp -r lib jni
39+
zip -r $$origdir/$(location :{}.aar) jni/*/*.so
40+
""".format(android_library, archive_name, archive_name, archive_name, archive_name),
41+
visibility = visibility,
42+
)

mobile/bazel/ranlib.patch

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- tools/build_defs/cmake_script.bzl
2+
+++ tools/build_defs/cmake_script.bzl
3+
@@ -91,6 +91,7 @@ _CMAKE_ENV_VARS_FOR_CROSSTOOL = {
4+
_CMAKE_CACHE_ENTRIES_CROSSTOOL = {
5+
"CMAKE_SYSTEM_NAME": struct(value = "CMAKE_SYSTEM_NAME", replace = True),
6+
"CMAKE_AR": struct(value = "CMAKE_AR", replace = True),
7+
+ "CMAKE_RANLIB": struct(value = "CMAKE_RANLIB", replace = True),
8+
"CMAKE_CXX_LINK_EXECUTABLE": struct(value = "CMAKE_CXX_LINK_EXECUTABLE", replace = True),
9+
"CMAKE_C_FLAGS": struct(value = "CMAKE_C_FLAGS_INIT", replace = False),
10+
"CMAKE_CXX_FLAGS": struct(value = "CMAKE_CXX_FLAGS_INIT", replace = False),

mobile/dist/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
load("@envoy//bazel:envoy_build_system.bzl", "envoy_package")
4+
load("@build_bazel_rules_apple//apple:apple.bzl", "apple_static_framework_import")
5+
6+
envoy_package()
7+
8+
# NOTE: You must first build the top-level targets //:ios_dist and //:android_dist to use the
9+
# artifacts referenced here.
10+
11+
aar_import(
12+
name = "envoy_mobile_android",
13+
aar = "envoy.aar",
14+
)
15+
16+
apple_static_framework_import(
17+
name = "envoy_mobile_ios",
18+
framework_imports = glob(["Envoy.framework/**"]),
19+
sdk_dylibs = [
20+
"resolv.9",
21+
"c++",
22+
],
23+
)

0 commit comments

Comments
 (0)