Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
licy183 committed Nov 25, 2024
1 parent 69d419a commit 8f438c7
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 49 deletions.
47 changes: 47 additions & 0 deletions packages/librusty-v8/0001-fix-clang-path.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
--- a/build/config/clang/BUILD.gn
+++ b/build/config/clang/BUILD.gn
@@ -227,7 +227,32 @@
assert(false) # Unhandled target platform
}

- _clang_lib_dir = "$clang_base_path/lib/clang/$clang_version/lib"
+ if (is_linux && (clang_base_path != default_clang_base_path)) {
+ _dir = "linux"
+ if (current_cpu == "x64") {
+ _suffix = "-x86_64"
+ } else if (current_cpu == "x86") {
+ _suffix = "-i386"
+ } else if (current_cpu == "arm64") {
+ _suffix = "-aarch64"
+ } else if (current_cpu == "arm") {
+ _suffix = "-arm"
+ } else {
+ assert(false) # Unhandled cpu type
+ }
+ }
+
+ _maybe_clang_base_path = clang_base_path
+ _maybe_clang_version = clang_version
+ if (is_android && (clang_base_path != default_clang_base_path)) {
+ if (android_ndk_clang_version == "") {
+ assert(false)
+ }
+ _maybe_clang_version = android_ndk_clang_version
+ _maybe_clang_base_path = "$android_toolchain_root"
+ }
+
+ _clang_lib_dir = "$_maybe_clang_base_path/lib/clang/$_maybe_clang_version/lib"
_lib_file = "${_prefix}clang_rt.${_libname}${_suffix}.${_ext}"
libs = [ "$_clang_lib_dir/$_dir/$_lib_file" ]
}
--- a/build/config/clang/clang.gni
+++ b/build/config/clang/clang.gni
@@ -39,6 +39,8 @@
# Set to true to enable output of ThinLTO index and import files used for
# creating a Chromium MLGO corpus in the ThinLTO case.
lld_emit_indexes_and_imports = false
+
+ android_ndk_clang_version = ""
}

# We don't really need to collect a corpus for the host tools, just for the target.
14 changes: 14 additions & 0 deletions packages/librusty-v8/0002-compiler-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -1913,6 +1913,11 @@
}
}

+ cflags += [
+ "-Wno-unknown-warning-option",
+ "-Wno-unknown-pragmas",
+ ]
+
# Rust warnings

# Require `unsafe` blocks even in `unsafe` fns. This is intended to become
20 changes: 20 additions & 0 deletions packages/librusty-v8/0003-build.rs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- a/build.rs
+++ b/build.rs
@@ -259,11 +259,17 @@
"x64"
} else if target_arch == "aarch64" {
"arm64"
+ } else if target_arch == "arm" {
+ "arm"
+ } else if target_triple.starts_with("i686-") {
+ "x86"
} else {
"unknown"
};
if target_arch == "x86_64" {
maybe_install_sysroot("amd64");
+ } else if target_triple.starts_with("i686-") {
+ maybe_install_sysroot("i386");
}
gn_args.push(format!(r#"v8_target_cpu="{}""#, arch).to_string());
gn_args.push(format!(r#"target_cpu="{}""#, arch).to_string());
19 changes: 0 additions & 19 deletions packages/librusty-v8/BUILD.gn.patch

This file was deleted.

62 changes: 32 additions & 30 deletions packages/librusty-v8/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,49 @@ TERMUX_PKG_SRCURL=git+https://github.com/denoland/rusty_v8
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_NO_STATICSPLIT=true

# to reduce compilation time
_SCCACHE_VERSION=0.8.2
_SCACCHE_SHA256=ecda4ddc89a49f1ec6f35bdce5ecbf6f205b399a680d11119d4ce9f6d962104e

termux_step_configure() {
termux_setup_rust
termux_setup_ninja
termux_setup_gn

GN="$(command -v gn)"
export GN

mkdir -p "${TERMUX_PKG_CACHEDIR}/sccache"
termux_download \
"https://github.com/mozilla/sccache/releases/download/v${_SCCACHE_VERSION}/sccache-v${_SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz" \
"${TERMUX_PKG_CACHEDIR}/sccache.tar.gz" \
"${_SCACCHE_SHA256}"
tar -zxf "${TERMUX_PKG_CACHEDIR}/sccache.tar.gz" --strip-components=1 -C "${TERMUX_PKG_CACHEDIR}/sccache"
export SCCACHE="${TERMUX_PKG_CACHEDIR}/sccache/sccache"
local _host_clang_version=17
local _target_clang_version=$($CC --version | grep -m1 version | sed -E 's|.*\bclang version ([0-9]+).*|\1|')
export EXTRA_GN_ARGS="
android32_ndk_api_level=$TERMUX_PKG_API_LEVEL
android64_ndk_api_level=$TERMUX_PKG_API_LEVEL
clang_version=\"$_host_clang_version\"
android_ndk_clang_version=\"$_target_clang_version\"
llvm_android_mainline=true
"

if [ "$TERMUX_ARCH" = "arm" ]; then
EXTRA_GN_ARGS+=" target_cpu = \"arm\""
EXTRA_GN_ARGS+=" v8_target_cpu = \"arm\""
EXTRA_GN_ARGS+=" arm_arch = \"armv7-a\""
EXTRA_GN_ARGS+=" arm_float_abi = \"softfp\""
fi

export GN="$(command -v gn)"
export CLANG_BASE_PATH="/usr/lib/llvm-$_host_clang_version"

cp -Rf "$NDK" "$TERMUX_PKG_SRCDIR"/third_party/android_ndk
mkdir -p third_party/android_toolchain
ln -sf ../../third_party/android_ndk "$TERMUX_PKG_SRCDIR"/third_party/android_toolchain/ndk

BINDGEN_EXTRA_CLANG_ARGS="--target=$CCTERMUX_HOST_PLATFORM"
BINDGEN_EXTRA_CLANG_ARGS+=" --sysroot=$TERMUX_PKG_SRCDIR/third_party/android_ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot"
export BINDGEN_EXTRA_CLANG_ARGS
local env_name=BINDGEN_EXTRA_CLANG_ARGS_${CARGO_TARGET_NAME@U}
env_name=${env_name//-/_}
export $env_name="$BINDGEN_EXTRA_CLANG_ARGS"
}

termux_step_make() {
export CLANG_BASE_PATH="${TERMUX_STANDALONE_TOOLCHAIN}/sysroot/usr"
# workaround for cargo to detect and use CI's clang/clang++
ln -s "${TERMUX_STANDALONE_TOOLCHAIN}/bin" "${CLANG_BASE_PATH}/bin"

export CARGO_CFG_TARGET_OS=android
case ${TERMUX_ARCH} in
i686) CARGO_CFG_TARGET_ARCH=x86 ;;
*) CARGO_CFG_TARGET_ARCH=${TERMUX_ARCH} ;;
esac
export CARGO_CFG_TARGET_ARCH

export TARGET="${TERMUX_HOST_PLATFORM}"

export DISABLE_CLANG=1

export V8_FROM_SOURCE=1
cargo build -vv --jobs "${TERMUX_PKG_MAKE_PROCESSES}" --target "${CARGO_TARGET_NAME}" --release
cargo build --jobs "${TERMUX_PKG_MAKE_PROCESSES}" --target "${CARGO_TARGET_NAME}" --release
}

termux_step_make_install() {
install -Dm600 -t "${TERMUX_PREFIX}/include/librusty_v8" "target/${CARGO_TARGET_NAME}/release/gn_out/src_binding.rs"
install -Dm600 -t "${TERMUX_PREFIX}/lib" "target/${CARGO_TARGET_NAME}/release/gn_out/obj/librusty_v8.a"
}
4 changes: 4 additions & 0 deletions scripts/setup-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ PACKAGES+=" llvm-17-dev"
PACKAGES+=" llvm-17-tools"
PACKAGES+=" clang-17"

# Needed by librusty-v8
PACKAGES+=" libclang-rt-17-dev"
PACKAGES+=" libclang-rt-17-dev:i386"

# Needed for package smalltalk.
PACKAGES+=" libsigsegv-dev"
PACKAGES+=" zip"
Expand Down

0 comments on commit 8f438c7

Please sign in to comment.