From 745261fd9c5410ed8ff1b912bdc0e5964aef6286 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 16:29:47 +0530 Subject: [PATCH 1/4] musl --- .github/workflows/ci.yml | 8 ++++++++ .gitmodules | 3 +++ build.rs | 33 +++++++++++++++++++++++++++++++++ config.mak | 7 +++++++ musl-cross-make | 1 + 5 files changed, 52 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 0ad9a38b81..e547754e70 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,6 +43,10 @@ jobs: target: x86_64-unknown-linux-gnu variant: release + - os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-22.04-xl' || 'ubuntu-22.04' }} + target: x86_64-unknown-linux-musl + variant: release + - os: ${{ github.repository == 'denoland/rusty_v8' && 'windows-2019-xxl' || 'windows-2019' }} target: x86_64-pc-windows-msvc variant: release # Note: we do not support windows debug builds. @@ -84,6 +88,10 @@ jobs: python-version: 3.11.x architecture: x64 + - 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' run: | diff --git a/.gitmodules b/.gitmodules index 5ff41bf655..33a4380837 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,6 @@ [submodule "third_party/abseil-cpp"] path = third_party/abseil-cpp url = https://chromium.googlesource.com/chromium/src/third_party/abseil-cpp.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 f890957918..9408b14aa8 100644 --- a/build.rs +++ b/build.rs @@ -123,6 +123,15 @@ fn build_v8() { vec!["is_debug=false".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 cfg!(not(feature = "use_custom_libcxx")) { gn_args.push("use_custom_libcxx=false".to_string()); } @@ -310,6 +319,30 @@ fn download_ninja_gn_binaries() { env::set_var("NINJA", ninja); } +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 0000000000..b6ed698591 --- /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 0000000000..26bb551045 --- /dev/null +++ b/musl-cross-make @@ -0,0 +1 @@ +Subproject commit 26bb55104559325b5e840911742220268f556d7a From dedba3087d3f0ac4a8c6698fbe52e6ff50294f96 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 18:08:48 +0530 Subject: [PATCH 2/4] musl --- build.rs | 48 ++++++++++++++++++++++++++++++++--------- config.mak | 4 ++-- toolchain/BUILD.gn | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 12 deletions(-) create mode 100644 toolchain/BUILD.gn diff --git a/build.rs b/build.rs index 9408b14aa8..b07b8b275c 100644 --- a/build.rs +++ b/build.rs @@ -123,15 +123,6 @@ fn build_v8() { vec!["is_debug=false".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 cfg!(not(feature = "use_custom_libcxx")) { gn_args.push("use_custom_libcxx=false".to_string()); } @@ -159,6 +150,40 @@ fn build_v8() { } } + if std::env::var("CARGO_CFG_TARGET_ENV").map_or(false, |e| e == "musl") { + let toolchain = build_musl_cross_make(); + + let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + let manifest_dir = Path::new(&manifest_dir).join("toolchain"); + let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + + gn_args.push("use_custom_libcxx=false".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()); + gn_args.push(format!("use_gold=false")); + gn_args.push(format!("use_sysroot=false")); + gn_args.push(format!("use_lld=false")); + gn_args.push("v8_static_library=true".to_string()); + gn_args.push("clang_use_chrome_plugins=false".to_string()); + gn_args.push(format!( + "custom_toolchain=\"{}:{}\"", + manifest_dir.display(), + arch + )); + + let target = std::env::var("TARGET").unwrap(); + env::set_var("TOOLCHAIN", toolchain.join("bin").display().to_string()); + env::set_var( + format!("CC_{}", target.replace("-", "_")), + format!( + "{}/bin/{}-cc", + toolchain.display(), + target.replace("-unknown-", "-") + ), + ); + } + if let Some(p) = env::var_os("SCCACHE") { cc_wrapper(&mut gn_args, Path::new(&p)); } else if let Ok(p) = which("sccache") { @@ -319,10 +344,11 @@ fn download_ninja_gn_binaries() { env::set_var("NINJA", ninja); } -fn build_musl_cross_make() { +fn build_musl_cross_make() -> PathBuf { let toolchain_dir = build_dir().join("musl-cross-make"); if toolchain_dir.exists() { println!("musl-cross-make toolchain already exists, skipping build"); + return toolchain_dir; } std::fs::copy("config.mak", "musl-cross-make/config.mak").unwrap(); @@ -341,6 +367,8 @@ fn build_musl_cross_make() { .arg(format!("OUTPUT={}", toolchain_dir.display())) .status() .unwrap(); + + toolchain_dir } fn static_lib_url() -> String { diff --git a/config.mak b/config.mak index b6ed698591..b89eb31891 100644 --- a/config.mak +++ b/config.mak @@ -1,5 +1,5 @@ -MUSL_VER = 1.1.24 -GCC_VER = 9.2.0 +MUSL_VER = 1.2.4 +GCC_VER = 11.2.0 GCC_CONFIG += --enable-default-pie diff --git a/toolchain/BUILD.gn b/toolchain/BUILD.gn new file mode 100644 index 0000000000..ee440669d5 --- /dev/null +++ b/toolchain/BUILD.gn @@ -0,0 +1,54 @@ +import("//build/config/sysroot.gni") +import("//build/toolchain/gcc_toolchain.gni") + +template("cross_toolchain") { + gcc_toolchain(target_name) { + assert(defined(invoker.toolprefix), "missing toolprefix") + + toolchain = getenv("TOOLCHAIN") + toolprefix = "${toolchain}/${invoker.toolprefix}" + + cc = "${toolprefix}-gcc" + cxx = "${toolprefix}-g++" + ld = cxx + + ar = "${toolprefix}-ar" + readelf = "${toolprefix}-readelf" + nm = "${toolprefix}-nm" + + extra_ldflags = "-static" + + toolchain_args = { + forward_variables_from(invoker.toolchain_args, "*") + use_remoteexec = false + is_clang = false + } + } +} + +cross_toolchain("aarch64") { + toolprefix = "aarch64-linux-musl" + + toolchain_args = { + current_cpu = "arm64" + current_os = "linux" + } +} + +cross_toolchain("armv7") { + toolprefix = "armv7-linux-musleabihf" + + toolchain_args = { + current_cpu = "arm" + current_os = "linux" + } +} + +cross_toolchain("x86_64") { + toolprefix = "x86_64-linux-musl" + + toolchain_args = { + current_cpu = "x64" + current_os = "linux" + } +} From 15ad593a25b754eee066950fdd56e5ed09bd7941 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 18:19:29 +0530 Subject: [PATCH 3/4] lint --- build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index b07b8b275c..41dd7fcea0 100644 --- a/build.rs +++ b/build.rs @@ -161,9 +161,9 @@ fn build_v8() { 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()); - gn_args.push(format!("use_gold=false")); - gn_args.push(format!("use_sysroot=false")); - gn_args.push(format!("use_lld=false")); + gn_args.push("use_gold=false".to_string()); + gn_args.push("use_sysroot=false".to_string()); + gn_args.push("use_lld=false".to_string()); gn_args.push("v8_static_library=true".to_string()); gn_args.push("clang_use_chrome_plugins=false".to_string()); gn_args.push(format!( @@ -175,7 +175,7 @@ fn build_v8() { let target = std::env::var("TARGET").unwrap(); env::set_var("TOOLCHAIN", toolchain.join("bin").display().to_string()); env::set_var( - format!("CC_{}", target.replace("-", "_")), + format!("CC_{}", target.replace('-', "_")), format!( "{}/bin/{}-cc", toolchain.display(), From 0f1dc252d7dfbd3d4b41d2703223321619775d63 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 29 Feb 2024 08:30:02 +0530 Subject: [PATCH 4/4] x --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 41dd7fcea0..6cdada26c8 100644 --- a/build.rs +++ b/build.rs @@ -166,6 +166,8 @@ fn build_v8() { gn_args.push("use_lld=false".to_string()); gn_args.push("v8_static_library=true".to_string()); gn_args.push("clang_use_chrome_plugins=false".to_string()); + // execinfo. is not available in musl + gn_args.push("is_debug=false".to_string()); gn_args.push(format!( "custom_toolchain=\"{}:{}\"", manifest_dir.display(),