From d3ae163b90312b8682481be8a552a4f2d512ca2f Mon Sep 17 00:00:00 2001 From: aimeedeer Date: Tue, 17 Oct 2023 21:56:53 -0600 Subject: [PATCH 1/4] add feature dwarf --- components/conformance-tests/tests/tests.rs | 1 + components/wasm-opt-sys/Cargo.toml | 4 ++++ components/wasm-opt-sys/build.rs | 17 ++++++++++++++--- components/wasm-opt/Cargo.toml | 4 ++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/conformance-tests/tests/tests.rs b/components/conformance-tests/tests/tests.rs index 2f48673..7fc392b 100644 --- a/components/conformance-tests/tests/tests.rs +++ b/components/conformance-tests/tests/tests.rs @@ -889,6 +889,7 @@ fn check_versions() -> Result<()> { } #[test] +#[cfg(feature = "dwarf")] fn dwarf_line_info() -> Result<()> { let infile = get_test_infile_wasm_alt()?; let outfile = PathBuf::from("outfile.wasm"); diff --git a/components/wasm-opt-sys/Cargo.toml b/components/wasm-opt-sys/Cargo.toml index 9387cdd..0f513bb 100644 --- a/components/wasm-opt-sys/Cargo.toml +++ b/components/wasm-opt-sys/Cargo.toml @@ -16,3 +16,7 @@ cxx-build = "1.0.79" [dependencies] cxx = "1.0.79" + +[features] +default = [] +dwarf = [] \ No newline at end of file diff --git a/components/wasm-opt-sys/build.rs b/components/wasm-opt-sys/build.rs index 1fae5d8..68e5c54 100644 --- a/components/wasm-opt-sys/build.rs +++ b/components/wasm-opt-sys/build.rs @@ -15,7 +15,9 @@ fn main() -> anyhow::Result<()> { let src_dir = binaryen_dir.join("src"); let src_files = get_src_files(&src_dir)?; + #[cfg(feature = "dwarf")] let llvm_dir = binaryen_dir.join("third_party/llvm-project"); + #[cfg(feature = "dwarf")] let llvm_files = get_llvm_files(&llvm_dir)?; let tools_dir = src_dir.join("tools"); @@ -35,8 +37,12 @@ fn main() -> anyhow::Result<()> { CFG.exported_header_dirs.push(&src_dir); CFG.exported_header_dirs.push(&tools_dir); CFG.exported_header_dirs.push(&output_dir); - let llvm_include = llvm_dir.join("include"); - CFG.exported_header_dirs.push(&llvm_include); + + #[cfg(feature = "dwarf")] + { + let llvm_include = llvm_dir.join("include"); + CFG.exported_header_dirs.push(&llvm_include); + } let mut builder = cxx_build::bridge("src/lib.rs"); @@ -49,6 +55,7 @@ fn main() -> anyhow::Result<()> { "-w", "-Wno-unused-parameter", "-DTHROW_ON_FATAL", + #[cfg(feature = "dwarf")] "-DBUILD_LLVM_DWARF", "-DNDEBUG", ] @@ -57,6 +64,7 @@ fn main() -> anyhow::Result<()> { "/std:c++17", "/w", "/DTHROW_ON_FATAL", + #[cfg(feature = "dwarf")] "/DBUILD_LLVM_DWARF", "/DNDEBUG", ] @@ -70,10 +78,12 @@ fn main() -> anyhow::Result<()> { builder .file(wasm_opt_main_shim) .files(src_files) - .files(&llvm_files) .file(wasm_opt_src) .file(wasm_intrinsics_src); + #[cfg(feature = "dwarf")] + builder.files(&llvm_files); + builder.compile("wasm-opt-cc"); Ok(()) @@ -356,6 +366,7 @@ fn check_cxx17_support() -> anyhow::Result<()> { Ok(()) } +#[cfg(feature = "dwarf")] fn get_llvm_files(llvm_dir: &Path) -> anyhow::Result<[PathBuf; 63]> { let llvm_dwarf = disambiguate_file(&llvm_dir.join("Dwarf.cpp"), "LLVMDwarf.cpp")?; let llvm_debug = disambiguate_file(&llvm_dir.join("Debug.cpp"), "LLVMDebug.cpp")?; diff --git a/components/wasm-opt/Cargo.toml b/components/wasm-opt/Cargo.toml index 2d33dbc..d6f9183 100644 --- a/components/wasm-opt/Cargo.toml +++ b/components/wasm-opt/Cargo.toml @@ -18,3 +18,7 @@ strum = "0.24" strum_macros = "0.24" thiserror = "1.0.32" tempfile = "3.3.0" + +[features] +default = [] +dwarf = ["wasm-opt-sys/dwarf"] \ No newline at end of file From 9cd7b86077920bfc5710fffb96093702fd41b8f8 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Oct 2023 13:35:55 -0600 Subject: [PATCH 2/4] Add dwarf CI config --- .github/workflows/ci.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d88aa8..5b7545e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,7 +117,17 @@ jobs: - uses: actions/checkout@v3 - name: Checkout submodule run: git submodule update --init --recursive - - run: cargo test --manifest-path components/conformance-tests/Cargo.toml + - run: cargo test --manifest-path components/conformance-tests/Cargo.toml + + dwarf: + name: Dwarf feature + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Checkout submodule + run: git submodule update --init --recursive + - run: cargo test --features=dwarf + - run: cargo test --features=dwarf --manifest-path components/conformance-tests/Cargo.toml fmt: name: Cargo fmt From 2650692ceaad8189b1d72c08b2a374179cb7358d Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Oct 2023 13:39:06 -0600 Subject: [PATCH 3/4] Add dwarf feature to conformance-tests --- components/conformance-tests/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/conformance-tests/Cargo.toml b/components/conformance-tests/Cargo.toml index ef5de33..70ce8cc 100644 --- a/components/conformance-tests/Cargo.toml +++ b/components/conformance-tests/Cargo.toml @@ -13,3 +13,7 @@ anyhow = "1.0.58" anyhow = "1.0.58" wasm-opt = { path = "../wasm-opt", version = "0.114.1" } tempfile = "3.3.0" + +[features] +default = [] +dwarf = ["wasm-opt/dwarf"] From 304464cdf979eb4a6da40c3ba245cb11f4cc8abb Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 18 Oct 2023 14:12:23 -0600 Subject: [PATCH 4/4] Dwarf testing fixes --- components/conformance-tests/build.rs | 11 ++++++++--- components/conformance-tests/tests/tests.rs | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/components/conformance-tests/build.rs b/components/conformance-tests/build.rs index f5da170..6f35a6b 100644 --- a/components/conformance-tests/build.rs +++ b/components/conformance-tests/build.rs @@ -64,10 +64,15 @@ fn build_binaryen_wasm_opt() -> Result<()> { fn build_rust_wasm_opt() -> Result<()> { let dirs = get_dirs()?; - let cargo_status = Command::new("cargo") + let mut cmd = Command::new("cargo"); + cmd .current_dir(dirs.workspace) - .args(["build", "-p", "wasm-opt", "--release"]) - .status()?; + .args(["build", "-p", "wasm-opt", "--release"]); + + #[cfg(feature = "dwarf")] + cmd.args(["--features", "dwarf"]); + + let cargo_status = cmd.status()?; if !cargo_status.success() { bail!("cargo failed"); diff --git a/components/conformance-tests/tests/tests.rs b/components/conformance-tests/tests/tests.rs index 7fc392b..90f9f84 100644 --- a/components/conformance-tests/tests/tests.rs +++ b/components/conformance-tests/tests/tests.rs @@ -251,6 +251,7 @@ fn get_test_infile_wasm() -> Result { Ok(infile) } +#[cfg(feature = "dwarf")] fn get_test_infile_wasm_alt() -> Result { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?; let manifest_dir = PathBuf::from(manifest_dir);