mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Make Android build optional on Nix (#31231)
* Make Android build optional on Nix I want to build Servo without also installing the entire Android SDK. This makes it so Android support is only built if `buildAndroid` is true. Signed-off-by: syvb <me@iter.ca> * Add Android support to nix-shell if SERVO_ANDROID_BUILD set --------- Signed-off-by: syvb <me@iter.ca>
This commit is contained in:
parent
92af41cfeb
commit
f27227b1db
3 changed files with 19 additions and 13 deletions
|
@ -1,6 +1,9 @@
|
||||||
# This provides a shell with all the necesarry packages required to run mach and build servo
|
# This provides a shell with all the necesarry packages required to run mach and build servo
|
||||||
# NOTE: This does not work offline or for nix-build
|
# NOTE: This does not work offline or for nix-build
|
||||||
|
|
||||||
|
{
|
||||||
|
buildAndroid ? false
|
||||||
|
}:
|
||||||
with import (builtins.fetchTarball {
|
with import (builtins.fetchTarball {
|
||||||
url = "https://github.com/NixOS/nixpkgs/archive/46ae0210ce163b3cba6c7da08840c1d63de9c701.tar.gz";
|
url = "https://github.com/NixOS/nixpkgs/archive/46ae0210ce163b3cba6c7da08840c1d63de9c701.tar.gz";
|
||||||
}) {
|
}) {
|
||||||
|
@ -11,8 +14,8 @@ with import (builtins.fetchTarball {
|
||||||
}))
|
}))
|
||||||
];
|
];
|
||||||
config = {
|
config = {
|
||||||
android_sdk.accept_license = true;
|
android_sdk.accept_license = buildAndroid;
|
||||||
allowUnfree = true;
|
allowUnfree = buildAndroid;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
let
|
let
|
||||||
|
@ -134,22 +137,16 @@ stdenv.mkDerivation rec {
|
||||||
|
|
||||||
RUSTC_BOOTSTRAP = "crown";
|
RUSTC_BOOTSTRAP = "crown";
|
||||||
}))
|
}))
|
||||||
|
|
||||||
# for android builds
|
|
||||||
# TODO: make this optional
|
|
||||||
openjdk17_headless
|
|
||||||
androidSdk
|
|
||||||
] ++ (lib.optionals stdenv.isDarwin [
|
] ++ (lib.optionals stdenv.isDarwin [
|
||||||
darwin.apple_sdk.frameworks.AppKit
|
darwin.apple_sdk.frameworks.AppKit
|
||||||
|
]) ++ (lib.optionals buildAndroid [
|
||||||
|
# for android builds
|
||||||
|
openjdk17_headless
|
||||||
|
androidSdk
|
||||||
]);
|
]);
|
||||||
|
|
||||||
LIBCLANG_PATH = llvmPackages.clang-unwrapped.lib + "/lib/";
|
LIBCLANG_PATH = llvmPackages.clang-unwrapped.lib + "/lib/";
|
||||||
|
|
||||||
# Required by ./mach build --android
|
|
||||||
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
|
|
||||||
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
|
|
||||||
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${buildToolsVersion}/aapt2";
|
|
||||||
|
|
||||||
# Allow cargo to download crates
|
# Allow cargo to download crates
|
||||||
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
|
||||||
|
|
||||||
|
@ -217,4 +214,9 @@ stdenv.mkDerivation rec {
|
||||||
export RUSTUP_HOME=$repo_root/.rustup
|
export RUSTUP_HOME=$repo_root/.rustup
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
} // lib.optionalAttrs buildAndroid {
|
||||||
|
# Required by ./mach build --android
|
||||||
|
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
|
||||||
|
ANDROID_NDK_ROOT = "${ANDROID_SDK_ROOT}/ndk-bundle";
|
||||||
|
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${ANDROID_SDK_ROOT}/build-tools/${buildToolsVersion}/aapt2";
|
||||||
}
|
}
|
||||||
|
|
3
mach
3
mach
|
@ -36,10 +36,11 @@ if __name__ == '__main__':
|
||||||
import subprocess
|
import subprocess
|
||||||
from shlex import quote
|
from shlex import quote
|
||||||
mach_dir = os.path.abspath(os.path.dirname(__file__))
|
mach_dir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
build_android_args = ['--arg', 'buildAndroid', 'true'] if 'SERVO_ANDROID_BUILD' in os.environ else []
|
||||||
print('NOTE: Entering nix-shell etc/shell.nix')
|
print('NOTE: Entering nix-shell etc/shell.nix')
|
||||||
try:
|
try:
|
||||||
# sys argv already contains the ./mach part, so we just need to pass it as-is
|
# sys argv already contains the ./mach part, so we just need to pass it as-is
|
||||||
result = subprocess.run(['nix-shell', mach_dir + '/etc/shell.nix', '--run', ' '.join(map(quote, sys.argv))])
|
result = subprocess.run(['nix-shell', mach_dir + '/etc/shell.nix'] + build_android_args + ['--run', ' '.join(map(quote, sys.argv))])
|
||||||
sys.exit(result.returncode)
|
sys.exit(result.returncode)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -537,6 +537,9 @@ class CommandBase(object):
|
||||||
if os.path.isdir(default):
|
if os.path.isdir(default):
|
||||||
env.setdefault(f"ANDROID_{kind.upper()}_ROOT", default)
|
env.setdefault(f"ANDROID_{kind.upper()}_ROOT", default)
|
||||||
|
|
||||||
|
if "IN_NIX_SHELL" in env and ("ANDROID_NDK_ROOT" not in env or "ANDROID_SDK_ROOT" not in env):
|
||||||
|
print("Please set SERVO_ANDROID_BUILD=1 when starting the Nix shell to include the Android SDK/NDK.")
|
||||||
|
sys.exit(1)
|
||||||
if "ANDROID_NDK_ROOT" not in env:
|
if "ANDROID_NDK_ROOT" not in env:
|
||||||
print("Please set the ANDROID_NDK_ROOT environment variable.")
|
print("Please set the ANDROID_NDK_ROOT environment variable.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue