Skip to content

Commit

Permalink
Merge pull request #156 from Aimeedeer/dwarf-feature
Browse files Browse the repository at this point in the history
add feature dwarf
  • Loading branch information
brson committed Oct 18, 2023
2 parents 7aa19c9 + 304464c commit 37247cd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions components/conformance-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
11 changes: 8 additions & 3 deletions components/conformance-tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions components/conformance-tests/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ fn get_test_infile_wasm() -> Result<PathBuf> {
Ok(infile)
}

#[cfg(feature = "dwarf")]
fn get_test_infile_wasm_alt() -> Result<PathBuf> {
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")?;
let manifest_dir = PathBuf::from(manifest_dir);
Expand Down Expand Up @@ -889,6 +890,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");
Expand Down
4 changes: 4 additions & 0 deletions components/wasm-opt-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ cxx-build = "1.0.79"

[dependencies]
cxx = "1.0.79"

[features]
default = []
dwarf = []
17 changes: 14 additions & 3 deletions components/wasm-opt-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");

Expand All @@ -49,6 +55,7 @@ fn main() -> anyhow::Result<()> {
"-w",
"-Wno-unused-parameter",
"-DTHROW_ON_FATAL",
#[cfg(feature = "dwarf")]
"-DBUILD_LLVM_DWARF",
"-DNDEBUG",
]
Expand All @@ -57,6 +64,7 @@ fn main() -> anyhow::Result<()> {
"/std:c++17",
"/w",
"/DTHROW_ON_FATAL",
#[cfg(feature = "dwarf")]
"/DBUILD_LLVM_DWARF",
"/DNDEBUG",
]
Expand All @@ -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(())
Expand Down Expand Up @@ -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")?;
Expand Down
4 changes: 4 additions & 0 deletions components/wasm-opt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit 37247cd

Please sign in to comment.