Skip to content

Commit

Permalink
Add support for Cargo workspaces in Rust integration (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobofan authored and devongovett committed Jun 5, 2018
1 parent dc10531 commit 24f28bc
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/assets/RustAsset.js
Expand Up @@ -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, '_');
Expand Down
6 changes: 6 additions & 0 deletions test/integration/rust-cargo-workspace/.eslintrc
@@ -0,0 +1,6 @@
{
"extends": "../.eslintrc.json",
"parserOptions": {
"sourceType": "module"
}
}
4 changes: 4 additions & 0 deletions test/integration/rust-cargo-workspace/Cargo.toml
@@ -0,0 +1,4 @@
[workspace]
members = [
"member"
]
9 changes: 9 additions & 0 deletions test/integration/rust-cargo-workspace/member/Cargo.toml
@@ -0,0 +1,9 @@
[package]
name = "member"
version = "0.1.0"
authors = ["josealbizures <albizures3601@gmail.com>"]

[dependencies]

[lib]
crate-type = ["cdylib"]
3 changes: 3 additions & 0 deletions 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);
});
4 changes: 4 additions & 0 deletions 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
}
30 changes: 30 additions & 0 deletions test/rust.js
Expand Up @@ -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);

Expand Down

0 comments on commit 24f28bc

Please sign in to comment.