From 8f438c72d9a090c2abfa8b6e874000eafe2bf5cd Mon Sep 17 00:00:00 2001 From: Chongyun Lee <45286352+licy183@users.noreply.github.com> Date: Mon, 25 Nov 2024 23:33:41 +0800 Subject: [PATCH] fix build --- .../librusty-v8/0001-fix-clang-path.patch | 47 ++++++++++++++ .../librusty-v8/0002-compiler-warnings.patch | 14 +++++ packages/librusty-v8/0003-build.rs.patch | 20 ++++++ packages/librusty-v8/BUILD.gn.patch | 19 ------ packages/librusty-v8/build.sh | 62 ++++++++++--------- scripts/setup-ubuntu.sh | 4 ++ 6 files changed, 117 insertions(+), 49 deletions(-) create mode 100644 packages/librusty-v8/0001-fix-clang-path.patch create mode 100644 packages/librusty-v8/0002-compiler-warnings.patch create mode 100644 packages/librusty-v8/0003-build.rs.patch delete mode 100644 packages/librusty-v8/BUILD.gn.patch diff --git a/packages/librusty-v8/0001-fix-clang-path.patch b/packages/librusty-v8/0001-fix-clang-path.patch new file mode 100644 index 000000000000000..6d7191a0b7319d1 --- /dev/null +++ b/packages/librusty-v8/0001-fix-clang-path.patch @@ -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. diff --git a/packages/librusty-v8/0002-compiler-warnings.patch b/packages/librusty-v8/0002-compiler-warnings.patch new file mode 100644 index 000000000000000..61d762271a45554 --- /dev/null +++ b/packages/librusty-v8/0002-compiler-warnings.patch @@ -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 diff --git a/packages/librusty-v8/0003-build.rs.patch b/packages/librusty-v8/0003-build.rs.patch new file mode 100644 index 000000000000000..13bf253f53aa241 --- /dev/null +++ b/packages/librusty-v8/0003-build.rs.patch @@ -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()); diff --git a/packages/librusty-v8/BUILD.gn.patch b/packages/librusty-v8/BUILD.gn.patch deleted file mode 100644 index d50a6c6c5758fc2..000000000000000 --- a/packages/librusty-v8/BUILD.gn.patch +++ /dev/null @@ -1,19 +0,0 @@ -diff --git a/BUILD.gn b/BUILD.gn -index 3de64b8..b3a0dd3 100644 ---- a/BUILD.gn -+++ b/BUILD.gn -@@ -47,4 +47,14 @@ config("rusty_v8_config") { - "-fansi-escape-codes", - ] - } -+ -+ cflags_c = [] -+ foreach(flag, string_split(getenv("CFLAGS"))) { -+ cflags_c += [ flag ] -+ } -+ -+ cflags_cc = [] -+ foreach(flag, string_split(getenv("CXXFLAGS"))) { -+ cflags_cc += [ flag ] -+ } - } diff --git a/packages/librusty-v8/build.sh b/packages/librusty-v8/build.sh index 600d39cedee3508..81b7b885d291a8e 100644 --- a/packages/librusty-v8/build.sh +++ b/packages/librusty-v8/build.sh @@ -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" } diff --git a/scripts/setup-ubuntu.sh b/scripts/setup-ubuntu.sh index 50fa9a7722a28fd..e89d12fa1ea5e7a 100755 --- a/scripts/setup-ubuntu.sh +++ b/scripts/setup-ubuntu.sh @@ -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"