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

Fix getting the target-dir in wasm_bindgen_build #1279

Merged
merged 2 commits into from
Jun 11, 2023
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
15 changes: 6 additions & 9 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,14 @@ pub fn wasm_bindgen_build(
};

let out_dir = out_dir.to_str().unwrap();
let has_target_dir_overwrite = extra_options.contains(&"--target-dir".to_string());
let target_directory = if has_target_dir_overwrite {
let i = extra_options
.binary_search(&"--target-dir".to_string())
.unwrap();
extra_options
.get(i + 1)

let target_directory = {
let mut has_target_dir_iter = extra_options.iter();
has_target_dir_iter
.find(|&it| it == "--target-dir")
.and_then(|_| has_target_dir_iter.next())
.map(Path::new)
.unwrap_or(data.target_directory())
} else {
data.target_directory()
};

let wasm_path = target_directory
Expand Down
14 changes: 14 additions & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() {
assert_eq!(pkg_path.join("licence").exists(), false);
}

#[test]
fn it_should_build_js_hello_world_example_with_custom_target_dir() {
let fixture = utils::fixture::js_hello_world();
fixture
.wasm_pack()
.arg("build")
.arg("--target-dir")
.arg("target2")
.arg("--all-features")
.arg("--offline")
.assert()
.success();
}

#[test]
fn it_should_build_crates_in_a_workspace() {
let fixture = utils::fixture::Fixture::new();
Expand Down