Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

musl libc builds (musl-cross-make) #1406

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -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.
Expand Down Expand Up @@ -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: |
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Expand Up @@ -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
63 changes: 63 additions & 0 deletions build.rs
Expand Up @@ -150,6 +150,42 @@ 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("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());
// execinfo. is not available in musl
gn_args.push("is_debug=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") {
Expand Down Expand Up @@ -310,6 +346,33 @@ fn download_ninja_gn_binaries() {
env::set_var("NINJA", ninja);
}

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();
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();

toolchain_dir
}

fn static_lib_url() -> String {
if let Ok(custom_archive) = env::var("RUSTY_V8_ARCHIVE") {
return custom_archive;
Expand Down
7 changes: 7 additions & 0 deletions config.mak
@@ -0,0 +1,7 @@
MUSL_VER = 1.2.4
GCC_VER = 11.2.0

GCC_CONFIG += --enable-default-pie

DL_CMD = curl -C - -L -s -o
SHA1_CMD = shasum -a 1 -c
1 change: 1 addition & 0 deletions musl-cross-make
Submodule musl-cross-make added at 26bb55
54 changes: 54 additions & 0 deletions 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"
}
}