From 0fc46338c0581d788bd46cbd81111d55ddd82523 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 16:29:47 +0530 Subject: [PATCH] musl --- .github/workflows/ci.yml | 8 ++++++++ .gitmodules | 3 +++ build.rs | 35 +++++++++++++++++++++++++++++++++++ config.mak | 7 +++++++ musl-cross-make | 1 + 5 files changed, 54 insertions(+) create mode 100644 config.mak create mode 160000 musl-cross-make diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 25d186b6..b2c10792 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,10 @@ jobs: variant: release cargo: cargo + - os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-24.04-xl' || 'ubuntu-24.04' }} + target: x86_64-unknown-linux-musl + variant: release + - os: ${{ github.repository == 'denoland/rusty_v8' && 'windows-2022-xxl' || 'windows-2022' }} target: x86_64-pc-windows-msvc variant: release # Note: we do not support windows debug builds. @@ -107,6 +111,10 @@ jobs: if: startsWith(matrix.config.os, 'ubuntu') run: | sudo apt-get install -y glib2.0 + + - name: Install cross compilation toolchain (musl) + if: endsWith(matrix.config.target, '-musl') + run: rustup target add ${{ matrix.config.target }} - name: Install cross compilation toolchain if: matrix.config.target == 'aarch64-unknown-linux-gnu' diff --git a/.gitmodules b/.gitmodules index 44ef796a..2ce5eadc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -37,3 +37,6 @@ [submodule "third_party/fast_float/src"] path = third_party/fast_float/src url = https://chromium.googlesource.com/external/github.com/fastfloat/fast_float.git +[submodule "musl-cross-make"] + path = musl-cross-make + url = https://github.com/richfelker/musl-cross-make.git diff --git a/build.rs b/build.rs index 4aead477..97e4ba7a 100644 --- a/build.rs +++ b/build.rs @@ -190,9 +190,20 @@ fn build_v8(is_asan: bool) { } else { vec!["is_debug=false".to_string()] }; + if is_asan { gn_args.push("is_asan=true".to_string()); } + + if std::env::var("CARGO_CFG_TARGET_ENV").map_or(false, |e| e == "musl") { + build_musl_cross_make(); + + gn_args.push("use_custom_libcxx=true".to_string()); + gn_args.push("is_clang=false".to_string()); + gn_args.push("treat_warnings_as_errors=false".to_string()); + gn_args.push("line_tables_only=false".to_string()); + } + if env::var("CARGO_FEATURE_USE_CUSTOM_LIBCXX").is_err() { gn_args.push("use_custom_libcxx=false".to_string()); } @@ -406,6 +417,30 @@ fn static_lib_name(suffix: &str) -> String { } } +fn build_musl_cross_make() { + let toolchain_dir = build_dir().join("musl-cross-make"); + if toolchain_dir.exists() { + println!("musl-cross-make toolchain already exists, skipping build"); + } + + std::fs::copy("config.mak", "musl-cross-make/config.mak").unwrap(); + Command::new("make") + .arg("-C") + .arg("musl-cross-make") + .arg("TARGET=x86_64-linux-musl") + .status() + .unwrap(); + + Command::new("make") + .arg("-C") + .arg("musl-cross-make") + .arg("TARGET=x86_64-linux-musl") + .arg("install") + .arg(format!("OUTPUT={}", toolchain_dir.display())) + .status() + .unwrap(); +} + fn static_lib_url() -> String { if let Ok(custom_archive) = env::var("RUSTY_V8_ARCHIVE") { return custom_archive; diff --git a/config.mak b/config.mak new file mode 100644 index 00000000..b6ed6985 --- /dev/null +++ b/config.mak @@ -0,0 +1,7 @@ +MUSL_VER = 1.1.24 +GCC_VER = 9.2.0 + +GCC_CONFIG += --enable-default-pie + +DL_CMD = curl -C - -L -s -o +SHA1_CMD = shasum -a 1 -c diff --git a/musl-cross-make b/musl-cross-make new file mode 160000 index 00000000..26bb5510 --- /dev/null +++ b/musl-cross-make @@ -0,0 +1 @@ +Subproject commit 26bb55104559325b5e840911742220268f556d7a