Skip to content

Commit

Permalink
support non-NixOS and CI; remove download code
Browse files Browse the repository at this point in the history
  • Loading branch information
mukilan committed Dec 2, 2023
1 parent 7c8809d commit e789008
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 35 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,14 @@ env:
RUST_BACKTRACE: 1
SHELL: /bin/bash
CARGO_INCREMENTAL: 0
RUST_FONTCONFIG_DLOPEN: "on" # FIXME: avoid link failure on fontconfig
HARFBUZZ_SYS_NO_PKG_CONFIG: "true"

jobs:
build:
name: Android Build
runs-on: ubuntu-22.04
strategy:
matrix:
#arch: ['armv7-linux-androideabi', 'i686-linux-android']
arch: ['armv7-linux-androideabi']
arch: ['armv7-linux-androideabi', 'i686-linux-android']
steps:
- uses: actions/checkout@v3
if: github.event_name != 'issue_comment' && github.event_name != 'pull_request_target'
Expand Down
18 changes: 11 additions & 7 deletions python/servo/bootstrap_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def bootstrap_android(self, build=False, emulator_x86=False, accept_all_licences
if not (build or emulator_x86):
print("Must specify `--build` or `--emulator-x86` or both.")

ndk = "android-ndk-r21d-{system}-{arch}"
tools = "sdk-tools-{system}-4333796"
ndk = "android-ndk-r25c-{system}"
tools = "commandlinetools-{system}-10406996_latest"

emulator_platform = "android-28"
emulator_platform = "android-30"
emulator_image = "system-images;%s;google_apis;x86" % emulator_platform

known_sha1 = {
Expand All @@ -99,6 +99,9 @@ def bootstrap_android(self, build=False, emulator_x86=False, accept_all_licences
"android-ndk-r19c-windows-x86_64.zip": "c4cd8c0b6e7618ca0a871a5f24102e40c239f6a3",
"android-ndk-r19c-darwin-x86_64.zip": "f46b8193109bba8a58e0461c1a48f4534051fb25",
"android-ndk-r21d-linux-x86_64.zip": "fd94d0be6017c6acbd193eb95e09cf4b6f61b834",
"android-ndk-r25c-linux.zip": "53af80a1cce9144025b81c78c8cd556bff42bd0e",

"commandlinetools-linux-10406996_latest": "dummy"
}

toolchains = path.join(self.context.topdir, "android-toolchains")
Expand Down Expand Up @@ -134,8 +137,8 @@ def download(target_dir, name, flatten=False):
machine = platform.machine().lower()
arch = {"i386": "x86"}.get(machine, machine)
if build:
download("ndk", ndk.format(system=system, arch=arch), flatten=True)
download("sdk", tools.format(system=system))
download("ndk", ndk.format(system=system), flatten=True)
download(path.join("sdk", "cmdline-tools", "latest"), tools.format(system=system), flatten=True)

components = []
if emulator_x86:
Expand All @@ -151,7 +154,8 @@ def download(target_dir, name, flatten=False):
"platforms;android-18",
]

sdkmanager = [path.join(toolchains, "sdk", "tools", "bin", "sdkmanager")] + components
tools_bin_dir = path.join(toolchains, "sdk", "cmdline-tools", "latest", "bin")
sdkmanager = [path.join(tools_bin_dir, "sdkmanager")] + components
if accept_all_licences:
yes = subprocess.Popen(["yes"], stdout=subprocess.PIPE)
process = subprocess.Popen(
Expand Down Expand Up @@ -189,7 +193,7 @@ def download(target_dir, name, flatten=False):
if emulator_x86:
avd_path = path.join(toolchains, "avd", "servo-x86")
process = subprocess.Popen(stdin=subprocess.PIPE, stdout=subprocess.PIPE, args=[
path.join(toolchains, "sdk", "tools", "bin", "avdmanager"),
path.join(tools_bin_dir, "avdmanager"),
"create", "avd",
"--path", avd_path,
"--name", "servo-x86",
Expand Down
52 changes: 28 additions & 24 deletions python/servo/command_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,28 +567,17 @@ def build_android_env_if_needed(self, env: Dict[str, str]):
if self.config["android"]["platform"]:
env["ANDROID_PLATFORM"] = self.config["android"]["platform"]

# These are set because they are the variable names that build-apk
# expects. However, other submodules have makefiles that reference
# the env var names above. Once winit is enabled and set as the
# default, we could modify the subproject makefiles to use the names
# below and remove the vars above, to avoid duplication.
if "ANDROID_SDK_ROOT" in env:
env["ANDROID_HOME"] = env["ANDROID_SDK_ROOT"]
if "ANDROID_NDK_ROOT" in env:
env["NDK_HOME"] = env["ANDROID_NDK_ROOT"]
if "ANDROID_TOOLCHAIN" in env:
env["NDK_STANDALONE"] = env["ANDROID_TOOLCHAIN"]

# FIXME: is this still needed?
toolchains = path.join(self.context.topdir, "android-toolchains")
for kind in ["sdk", "ndk"]:
default = os.path.join(toolchains, kind)
if os.path.isdir(default):
env.setdefault("ANDROID_" + kind.upper(), default)
env.setdefault(f"ANDROID_{kind.upper()}_ROOT", default)

tools = os.path.join(toolchains, "sdk", "platform-tools")
if os.path.isdir(tools):
env["PATH"] = "%s%s%s" % (tools, os.pathsep, env["PATH"])
# FIXME: is this still needed?
#tools = os.path.join(toolchains, "sdk", "platform-tools")
#if os.path.isdir(tools):
#env["PATH"] = "%s%s%s" % (tools, os.pathsep, env["PATH"])

if "ANDROID_NDK_ROOT" not in env:
print("Please set the ANDROID_NDK_ROOT environment variable.")
Expand All @@ -597,6 +586,17 @@ def build_android_env_if_needed(self, env: Dict[str, str]):
print("Please set the ANDROID_SDK_ROOT environment variable.")
sys.exit(1)

# These are set because they are the variable names that build-apk
# expects. However, other submodules have makefiles that reference
# the env var names above. Once winit is enabled and set as the
# default, we could modify the subproject makefiles to use the names
# below and remove the vars above, to avoid duplication.
env["ANDROID_HOME"] = env["ANDROID_SDK_ROOT"]
env["NDK_HOME"] = env["ANDROID_NDK_ROOT"]

if "ANDROID_TOOLCHAIN" in env:
env["NDK_STANDALONE"] = env["ANDROID_TOOLCHAIN"]

android_platform = self.config["android"]["platform"]
android_toolchain_name = self.config["android"]["toolchain_name"]
android_toolchain_prefix = self.config["android"]["toolchain_prefix"]
Expand Down Expand Up @@ -656,15 +656,16 @@ def build_android_env_if_needed(self, env: Dict[str, str]):
#clang_include = path.join(llvm_toolchain, "lib64", "clang", "5.0", "include")
android_api = android_platform.replace('android-', '')

to_ndk_bin = lambda prog: path.join(llvm_toolchain, "bin", prog)
env["ANDROID_NDK_HOME"] = env["ANDROID_NDK_ROOT"]
env["RUST_TARGET"] = self.cross_compile_target
env['HOST_CC'] = host_cc
env['HOST_CXX'] = host_cxx
env['HOST_CFLAGS'] = ''
env['HOST_CXXFLAGS'] = ''
env['CC'] = path.join(llvm_toolchain, "bin", "clang")
env['CPP'] = path.join(llvm_toolchain, "bin", "clang") + " -E"
env['CXX'] = path.join(llvm_toolchain, "bin", "clang++")
env['CC'] = to_ndk_bin("clang")
env['CPP'] = to_ndk_bin("clang") + " -E"
env['CXX'] = to_ndk_bin("clang++")
env['ANDROID_API_LEVEL'] = "30"
env['ANDROID_TOOLCHAIN'] = gcc_toolchain
env['ANDROID_TOOLCHAIN_DIR'] = gcc_toolchain
Expand All @@ -674,11 +675,14 @@ def build_android_env_if_needed(self, env: Dict[str, str]):
# env['GCC_TOOLCHAIN'] = gcc_toolchain
#gcc_toolchain_bin = path.join(gcc_toolchain, android_toolchain_name, "bin")

env['AR'] = check_output([env['CC'], "--print-prog-name=ar"]).strip()
env['RANLIB'] = check_output([env['CC'], "--print-prog-name=ranlib"]).strip()
env['OBJCOPY'] = check_output([env['CC'], "--print-prog-name=objcopy"]).strip()
env['YASM'] = check_output([env['CC'], "--print-prog-name=yasm"]).strip()
env['STRIP'] = check_output([env['CC'], "--print-prog-name=strip"]).strip()
env['AR'] = to_ndk_bin("llvm-ar")
env['RANLIB'] = to_ndk_bin("llvm-ranlib")
env['OBJCOPY'] = to_ndk_bin("llvm-objcopy")
env['YASM'] = to_ndk_bin("yasm")
env['STRIP'] = to_ndk_bin("llvm-strip")
env['LLVM_CONFIG_PATH'] = to_ndk_bin("llvm-config")
env['HARFBUZZ_SYS_NO_PKG_CONFIG'] = "true"
env['RUST_FONTCONFIG_DLOPEN'] = "on"
# A cheat-sheet for some of the build errors caused by getting the search path wrong...
#
# fatal error: 'limits' file not found
Expand Down

0 comments on commit e789008

Please sign in to comment.