Skip to content

Commit

Permalink
Remove wasm-gc from RustAsset (#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored and devongovett committed Sep 25, 2018
1 parent 43a0f5e commit 6844492
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 74 deletions.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -126,7 +126,8 @@
"minify": "terser -c -m -o src/builtins/prelude.min.js src/builtins/prelude.js && terser -c -m -o src/builtins/prelude2.min.js src/builtins/prelude2.js",
"precommit": "lint-staged",
"lint": "eslint . && prettier \"./{src,bin,test}/**/*.{js,json,md}\" --list-different",
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\""
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove Parcel? You can now donate to our open collective:\\u001b[22m\\u001b[39m\\n > \\u001b[34mhttps://opencollective.com/parcel/donate\\u001b[0m')\"",
"clean": "rm -rf node_modules lib && yarn"
},
"bin": {
"parcel": "bin/cli.js"
Expand Down
26 changes: 1 addition & 25 deletions src/assets/RustAsset.js
Expand Up @@ -15,7 +15,6 @@ const MAIN_FILES = ['src/lib.rs', 'src/main.rs'];

// Track installation status so we don't need to check more than once
let rustInstalled = false;
let wasmGCInstalled = false;

class RustAsset extends Asset {
constructor(name, options) {
Expand Down Expand Up @@ -62,12 +61,6 @@ class RustAsset extends Asset {
} else {
await this.rustcBuild();
}

// If this is a prod build, use wasm-gc to remove unused code
if (this.options.minify) {
await this.installWasmGC();
await exec('wasm-gc', [this.wasmPath, this.wasmPath]);
}
}

async installRust() {
Expand Down Expand Up @@ -111,24 +104,6 @@ class RustAsset extends Asset {
rustInstalled = true;
}

async installWasmGC() {
if (wasmGCInstalled) {
return;
}

try {
await commandExists('wasm-gc');
} catch (e) {
await pipeSpawn('cargo', [
'install',
'--git',
'https://github.com/alexcrichton/wasm-gc'
]);
}

wasmGCInstalled = true;
}

async cargoBuild(cargoConfig, cargoDir) {
// Ensure the cargo config has cdylib as the crate-type
if (!cargoConfig.lib) {
Expand Down Expand Up @@ -182,6 +157,7 @@ class RustAsset extends Asset {
'-o',
this.wasmPath
];

await exec('rustc', args);

// Run again to collect dependencies
Expand Down
48 changes: 0 additions & 48 deletions test/rust.js
Expand Up @@ -168,52 +168,4 @@ describe('rust', function() {
var res = await run(b);
assert.equal(res, 5);
});

it('should use wasm-gc to minify output', async function() {
this.timeout(500000);

// Store the size of not minified bundle in order to test it against
// the size of minified one.
let b = await bundle(path.join(__dirname, '/integration/rust/index.js'), {
minify: false,
sourceMaps: false
});
const size = (await fs.stat(Array.from(b.childBundles)[0].name)).size;

let bMinified = await bundle(
path.join(__dirname, '/integration/rust/index.js'),
{
minify: true,
sourceMaps: false
}
);

const bundleTree = {
name: 'index.js',
assets: [
'bundle-loader.js',
'bundle-url.js',
'index.js',
'wasm-loader.js'
],
childBundles: [
{
type: 'wasm',
assets: ['add.rs'],
childBundles: []
}
]
};

await assertBundleTree(b, bundleTree);
await assertBundleTree(bMinified, bundleTree);

var res = await run(bMinified);
assert.equal(res, 5);

const sizeMinified = (await fs.stat(
Array.from(bMinified.childBundles)[0].name
)).size;
assert(sizeMinified < size);
});
});

0 comments on commit 6844492

Please sign in to comment.