From 0fc46338c0581d788bd46cbd81111d55ddd82523 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 16:29:47 +0530 Subject: [PATCH 1/7] 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 25d186b6a9..b2c1079287 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 44ef796ab5..2ce5eadc4c 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 4aead47749..97e4ba7a68 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 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 14f218a60bb7baadc62b65e8fe51b9b1413ce5aa Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 18:08:48 +0530 Subject: [PATCH 2/7] musl --- build.rs | 39 ++++++++++++++++++++++++++++++++- config.mak | 4 ++-- toolchain/BUILD.gn | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 toolchain/BUILD.gn diff --git a/build.rs b/build.rs index 97e4ba7a68..5b8c911e9c 100644 --- a/build.rs +++ b/build.rs @@ -231,6 +231,40 @@ fn build_v8(is_asan: bool) { } } + 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") { @@ -417,10 +451,11 @@ fn static_lib_name(suffix: &str) -> String { } } -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(); @@ -439,6 +474,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 95a18e1496a9f730c62af0b5ceaff88fed514ccd Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 28 Feb 2024 18:19:29 +0530 Subject: [PATCH 3/7] lint --- build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 5b8c911e9c..9a3fa7d9f4 100644 --- a/build.rs +++ b/build.rs @@ -242,9 +242,9 @@ fn build_v8(is_asan: bool) { 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!( @@ -256,7 +256,7 @@ fn build_v8(is_asan: bool) { 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 4307d44c51cd0bdc42afa2269ca935ad3da2bc3f Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 29 Feb 2024 08:30:02 +0530 Subject: [PATCH 4/7] x --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index 9a3fa7d9f4..10f45f3264 100644 --- a/build.rs +++ b/build.rs @@ -247,6 +247,8 @@ fn build_v8(is_asan: bool) { 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(), From 23996cde4b5a3a9b7f0399271e9378f4334635ff Mon Sep 17 00:00:00 2001 From: Ronny Chan Date: Thu, 24 Oct 2024 11:02:44 -0400 Subject: [PATCH 5/7] update musl-cross-make --- musl-cross-make | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/musl-cross-make b/musl-cross-make index 26bb551045..fd6be58297 160000 --- a/musl-cross-make +++ b/musl-cross-make @@ -1 +1 @@ -Subproject commit 26bb55104559325b5e840911742220268f556d7a +Subproject commit fd6be58297ee21fcba89216ccd0d4aca1e3f1c5c From 54a958ba21faf0d9791414fdfaffeed88ad9ed10 Mon Sep 17 00:00:00 2001 From: Ronny Chan Date: Thu, 24 Oct 2024 11:07:35 -0400 Subject: [PATCH 6/7] add cargo to matrix --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2c1079287..f6a4cab6cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,7 @@ jobs: - os: ${{ github.repository == 'denoland/rusty_v8' && 'ubuntu-24.04-xl' || 'ubuntu-24.04' }} target: x86_64-unknown-linux-musl variant: release + cargo: cargo - os: ${{ github.repository == 'denoland/rusty_v8' && 'windows-2022-xxl' || 'windows-2022' }} target: x86_64-pc-windows-msvc @@ -111,7 +112,7 @@ 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 }} From b047294c87962a67b3197179a22cb62f8c7ac565 Mon Sep 17 00:00:00 2001 From: Ronny Chan Date: Thu, 24 Oct 2024 13:08:06 -0400 Subject: [PATCH 7/7] set cargo linker --- build.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.rs b/build.rs index 10f45f3264..8107d2acda 100644 --- a/build.rs +++ b/build.rs @@ -265,6 +265,14 @@ fn build_v8(is_asan: bool) { target.replace("-unknown-", "-") ), ); + env::set_var( + format!("CARGO_TARGET_{}_LINKER", target.replace('-', "_")), + format!( + "{}/bin/{}-gcc", + toolchain.display(), + target.replace("-unknown-", "-") + ), + ); } if let Some(p) = env::var_os("SCCACHE") {