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

feat(api/build/v8): Use blob to build v8 #5146

Merged
merged 6 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup MSVC (Windows)
uses: ilammy/msvc-dev-cmd@v1
if: matrix.metadata.build == 'windows-x64'

- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.MSRV }}
Expand All @@ -297,9 +301,10 @@ jobs:
run: |
choco install ninja

- name: Setup MSVC (Windows)
uses: ilammy/msvc-dev-cmd@v1
if: matrix.metadata.build == 'windows-x64'
- name: Delete unwanted link to stop it from interfering (Windows)
shell: bash
run: rm /usr/bin/link.exe
if: startsWith(matrix.metadata.build, 'windows-')

- name: Test WAMR API
if: ${{ matrix.build-what.key == 'wamr' }}
Expand Down
58 changes: 52 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ test-examples: test-stage-5-test-examples test-stage-6-test-examples-release
test-v8: test-v8-api

test-v8-api:
cargo nextest run --package=wasmer --release --features=v8 --no-default-features
CARGO_TERM_VERBOSE=true cargo nextest run --package=wasmer --release --features=v8 --no-default-features

test-wamr: test-wamr-api

Expand Down
2 changes: 2 additions & 0 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ static-artifact-create = ["wasmer-compiler/static-artifact-create"]
[build-dependencies]
bindgen = "0.70.1"
cmake = "0.1.50"
tar = "0.4.42"
ureq = "2.10.1"
xz = "0.1.0"
zip = "2.2.0"

[package.metadata.docs.rs]
Expand Down
79 changes: 30 additions & 49 deletions lib/api/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,58 +148,41 @@ fn main() {

#[cfg(feature = "v8")]
{
use cmake::Config;
use std::{env, path::PathBuf};

let url = match (env::var("CARGO_CFG_TARGET_OS").unwrap().as_str(), env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str()) {
("macos", "aarch64") => "https://github.com/wasmerio/wee8-custom-builds/releases/download/11.6/wee8-darwin-aarch64.tar.xz",
("macos", "x86_64") => "https://github.com/wasmerio/wee8-custom-builds/releases/download/11.6/wee8-darwin-amd64.tar.xz",
("linux", "x86_64") => "https://github.com/wasmerio/wee8-custom-builds/releases/download/11.6/wee8-linux-amd64.tar.xz",
("windows", "x86_64") =>"https://github.com/wasmerio/wee8-custom-builds/releases/download/11.6/wee8-windows-amd64.tar.xz",
(os, arch) => panic!("target os + arch combination not supported: {os}, {arch}")
};

let crate_root = env::var("CARGO_MANIFEST_DIR").unwrap();
let v8_cmake_dir = PathBuf::from(&crate_root)
.join("third_party")
.join("v8-cmake");

let mut fetch_submodules = std::process::Command::new("git");
fetch_submodules
.current_dir(crate_root)
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive");

let res = fetch_submodules.output();

if let Err(e) = res {
panic!("fetching submodules failed: {e}");
}
let v8_dir = PathBuf::from(&crate_root).join("third_party").join("v8");
let out_dir = env::var("OUT_DIR").unwrap();

let mut dst = Config::new(v8_cmake_dir.clone());
let tar = ureq::get(url).call().expect("failed to download v8");

dst.always_configure(true)
.generator("Ninja")
.define(
"CMAKE_BUILD_TYPE",
if cfg!(debug_assertions) {
"RelWithDebInfo"
} else {
"Release"
},
)
.build_target("wee8");
let mut tar_data = Vec::new();
tar.into_reader()
.read_to_end(&mut tar_data)
.expect("failed to download v8 lib");

if cfg!(target_os = "windows") {
dst.define("CMAKE_CXX_COMPILER", "cl.exe");
dst.define("CMAKE_C_COMPILER", "cl.exe");
dst.define("CMAKE_LINKER_TYPE", "MSVC");
dst.define("WAMR_BUILD_PLATFORM", "windows");
let tar = xz::read::XzDecoder::new(tar_data.as_slice());
let mut archive = tar::Archive::new(tar);

for entry in archive.entries().unwrap() {
eprintln!("entry: {:?}", entry.unwrap().path());
}

let dst = dst.build();
let tar = xz::read::XzDecoder::new(tar_data.as_slice());
let mut archive = tar::Archive::new(tar);

archive.unpack(out_dir.clone()).unwrap();

println!("cargo:rustc-link-search=native={}", out_dir);

// Check output of `cargo build --verbose`, should see something like:
// -L native=/path/runng/target/debug/build/runng-sys-abc1234/out
// That contains output from cmake
println!(
"cargo:rustc-link-search=native={}",
dst.join("build").display()
);
println!("cargo:rustc-link-lib=wee8");
println!("cargo:rustc-link-lib=v8_initializers");
println!("cargo:rustc-link-lib=v8_libbase");
Expand All @@ -214,17 +197,15 @@ fn main() {
println!("cargo:rustc-link-lib=stdc++");
} else if cfg!(target_os = "windows") {
/* do nothing */
println!("cargo:rustc-link-lib=winmm");
println!("cargo:rustc-link-lib=dbghelp");
println!("cargo:rustc-link-lib=shlwapi");
} else {
println!("cargo:rustc-link-lib=c++");
}

let bindings = bindgen::Builder::default()
.header(
v8_cmake_dir
.join("v8/third_party/wasm-api/wasm.h")
.to_str()
.unwrap(),
)
.header(v8_dir.join("wasm.h").to_str().unwrap())
.derive_default(true)
.derive_debug(true)
.generate()
Expand Down
Loading
Loading