diff --git a/src/assets/RustAsset.js b/src/assets/RustAsset.js index 4bd8c78179e..aaef8f61df0 100644 --- a/src/assets/RustAsset.js +++ b/src/assets/RustAsset.js @@ -152,7 +152,12 @@ class RustAsset extends Asset { await exec('cargo', args, {cwd: cargoDir}); // Get output file paths - let outDir = path.join(cargoDir, 'target', RUST_TARGET, 'release'); + let [stdout] = await exec('cargo', ['metadata', '--format-version', '1'], { + cwd: cargoDir + }); + const cargoMetadata = JSON.parse(stdout); + const cargoTargetDir = cargoMetadata.target_directory; + let outDir = path.join(cargoTargetDir, RUST_TARGET, 'release'); // Rust converts '-' to '_' when outputting files. let rustName = cargoConfig.package.name.replace(/-/g, '_'); diff --git a/test/integration/rust-cargo-workspace/.eslintrc b/test/integration/rust-cargo-workspace/.eslintrc new file mode 100644 index 00000000000..38d01a2adca --- /dev/null +++ b/test/integration/rust-cargo-workspace/.eslintrc @@ -0,0 +1,6 @@ +{ + "extends": "../.eslintrc.json", + "parserOptions": { + "sourceType": "module" + } +} diff --git a/test/integration/rust-cargo-workspace/Cargo.toml b/test/integration/rust-cargo-workspace/Cargo.toml new file mode 100644 index 00000000000..ff5e5a3d2b1 --- /dev/null +++ b/test/integration/rust-cargo-workspace/Cargo.toml @@ -0,0 +1,4 @@ +[workspace] +members = [ + "member" +] diff --git a/test/integration/rust-cargo-workspace/member/Cargo.toml b/test/integration/rust-cargo-workspace/member/Cargo.toml new file mode 100644 index 00000000000..a4d5beae4a3 --- /dev/null +++ b/test/integration/rust-cargo-workspace/member/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "member" +version = "0.1.0" +authors = ["josealbizures "] + +[dependencies] + +[lib] +crate-type = ["cdylib"] diff --git a/test/integration/rust-cargo-workspace/member/src/index.js b/test/integration/rust-cargo-workspace/member/src/index.js new file mode 100644 index 00000000000..1e436ceeaea --- /dev/null +++ b/test/integration/rust-cargo-workspace/member/src/index.js @@ -0,0 +1,3 @@ +module.exports = import('./lib.rs').then(function ({add}) { + return add(2, 3); +}); diff --git a/test/integration/rust-cargo-workspace/member/src/lib.rs b/test/integration/rust-cargo-workspace/member/src/lib.rs new file mode 100644 index 00000000000..2ec8e0327e4 --- /dev/null +++ b/test/integration/rust-cargo-workspace/member/src/lib.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub fn add(a: i32, b: i32) -> i32 { + return a + b +} diff --git a/test/rust.js b/test/rust.js index 69232368b0f..d96163d0419 100644 --- a/test/rust.js +++ b/test/rust.js @@ -133,6 +133,36 @@ describe('rust', function() { assert.equal(res, 5); }); + it('should generate a wasm file from a rust file in cargo workspace', async function() { + this.timeout(500000); + let b = await bundle( + __dirname + '/integration/rust-cargo-workspace/member/src/index.js' + ); + + await assertBundleTree(b, { + name: 'index.js', + assets: [ + 'bundle-loader.js', + 'bundle-url.js', + 'index.js', + 'wasm-loader.js' + ], + childBundles: [ + { + type: 'map' + }, + { + type: 'wasm', + assets: ['lib.rs'], + childBundles: [] + } + ] + }); + + var res = await run(b); + assert.equal(res, 5); + }); + it('should use wasm-gc to minify output', async function() { this.timeout(500000);