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

Does wasm-bindgen search output artifacts based on $CARGO_TARGET_DIR ? #962

Closed
huangjj27 opened this issue Oct 13, 2018 · 3 comments
Closed

Comments

@huangjj27
Copy link
Member

In the past week, I was trying to fix rustwasm/wasm-pack#390. Then, I write a test case as follow:

#[cfg(target_os = "windows")]
#[test]
fn it_format_out_dir_on_windows() {
    let fixture = utils::fixture::js_hello_world();
    fixture.install_local_wasm_bindgen();
    let cli = Cli::from_iter_safe(vec![
        "wasm-pack",
        "build",
        &fixture.path.display().to_string(),
    ])
    .unwrap();
    let logger = logger::new(&cli.cmd, 3).unwrap();
    let result =
        command::run_wasm_pack(cli.cmd, &logger).expect("js_hello_world example should pass");

    let wasm_pack_log = utils::file::read_file(&fixture.path.join("wasm-pack.log")).unwrap();
    assert!(
        wasm_pack_log.contains(r"Your wasm pkg is ready to publish at \\?\C:\Users\"),
        "directories in wasm-pack.log should be well formatted",
    );
}

the test generate a temp project directory c:\Users\34937\Documents\wasm-pack\target\t\.tmpfrYWhr\wasm-pack, let's call it the tmp_wasm_pack.
But, In the wasm-pack.log generated at the tmp_wasm_pack, it complains that a wasm file is not found:

error: failed to read `target/wasm32-unknown-unknown/release/js_hello_world.wasm`
	caused by: 系统找不到指定的路径。 (os error 3)      # system can't find the path

What I discover, is that in order to reuse artifacts, the $CARGO_TARGET_DIR of tmp_wasm_pack is set to the same target directory as wasm-pack's, declared at:

// tests/utils/fixture.rs line 28-48
impl Fixture {
    /// Create a new test fixture in a temporary directory.
    pub fn new() -> Fixture {
        // Make sure that all fixtures end up sharing a target dir, and we don't
        // recompile wasm-bindgen and friends many times over.
        static SET_TARGET_DIR: Once = ONCE_INIT;
        let target_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target");
        SET_TARGET_DIR.call_once(|| {
            env::set_var("CARGO_TARGET_DIR", &target_dir);
        });

        let root = target_dir.join("t");
        fs::create_dir_all(&root).unwrap();
        let dir = TempDir::new_in(&root).unwrap();
        let path = dir.path().join("wasm-pack");
        eprintln!("Created fixture at {}", path.display());
        Fixture {
            dir: ManuallyDrop::new(dir),
            path,
        }
    }

    // omitting...
}

I believe it's the reset of $CARGO_TARGET_DIR that causes the problem when running wasm-bindgen in wasm-pack, and I wonder if wasm-bindgen searches output artifacts based on $CARGO_TARGET_DIR. If so, wasm-bindgen should find out these artifacts lay in `wasm-pack/target/wasm32-unknown-unknown

@alexcrichton
Copy link
Contributor

Currently wasm-bindgen doesn't do any searching around, it only uses the path that's passed in. The wasm-bindgen-test-runner does do some inference based on the input path, but it also doesn't do any searching. I think this may be a bug in the test perhaps?

@huangjj27
Copy link
Member Author

thanks, I will do more research to locate the reason.

@huangjj27
Copy link
Member Author

huangjj27 commented Oct 15, 2018

I found that it is caused by rustwasm/wasm-pack#414. The issue is closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants