Skip to content

Commit

Permalink
Programmatically generate rust.d.ts
Browse files Browse the repository at this point in the history
Hurray for less duplication! This should also help ensure that the Rust/JS
bridge remains well typed.
  • Loading branch information
alexcrichton committed Dec 8, 2017
1 parent 1748e41 commit af48783
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 54 deletions.
30 changes: 22 additions & 8 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,38 @@ module.exports = function(_options) {
destDir: 'packages/@glimmer'
});

let wasmTree = new Rust('packages/@glimmer/low-level/rust', {
generateWrapper: true,
generateTypescript: true,
});

// The rust compilation will emit a `*.d.ts` file which describes the JS
// interface of the wasm module, so let's pull that in to feed it into
// typescript.
let wasmTypeDefinitions = funnel(wasmTree, {
destDir: 'packages/@glimmer/low-level/lib',
});
tsTree = merge([tsTree, wasmTypeDefinitions]);

// Second, compile all of the TypeScript into ES2017 JavaScript. Because the
// TypeScript compiler understands the project as a whole, it's faster to do
// this once and use the transpiled JavaScript as the input to any further
// transformations.
let jsTree = typescript(tsTree);

// The rust compilation *also* emitted a `*.js` file which is what we actually
// want in terms of compiling it all together, so let's pull that into the
// output of the typescript tree to make sure the module can actually get
// resolved!
let wasmRuntimeFiles = funnel(wasmTree, {
destDir: '@glimmer/low-level/lib',
});
jsTree = merge([jsTree, wasmRuntimeFiles]);

// The TypeScript compiler doesn't emit `.d.ts` files, so we need to manually
// merge them back into our JavaScript output.
jsTree = mergeDefinitionFiles(jsTree);

let wasmTree = new Rust('packages/@glimmer/low-level/rust', {
generateWrapper: true,
});
wasmTree = funnel(wasmTree, {
destDir: '@glimmer/low-level/lib',
});
jsTree = merge([jsTree, wasmTree]);

// Glimmer includes a number of assertions and logging information that can be
// stripped from production builds for better runtime performance.
if (PRODUCTION) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"broccoli-merge-trees": "^1.1.1",
"broccoli-persistent-filter": "^1.2.13",
"broccoli-rollup": "^2.0.0",
"broccoli-rust2wasm": "^0.3.0",
"broccoli-rust2wasm": "^0.3.1",
"broccoli-source": "^1.1.0",
"broccoli-tslinter": "^2.0.0",
"broccoli-typescript-compiler": "^2.0.0",
Expand Down
42 changes: 0 additions & 42 deletions packages/@glimmer/low-level/lib/rust.d.ts

This file was deleted.

11 changes: 8 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1633,11 +1633,12 @@ broccoli-rollup@^2.0.0:
symlink-or-copy "^1.1.8"
walk-sync "^0.3.1"

broccoli-rust2wasm@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/broccoli-rust2wasm/-/broccoli-rust2wasm-0.3.0.tgz#8621477764718b648ca70c64a34f53af6d9c6d08"
broccoli-rust2wasm@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/broccoli-rust2wasm/-/broccoli-rust2wasm-0.3.1.tgz#44662fe65e2bb147411bb11c122dd5d708f98708"
dependencies:
broccoli-plugin "^1.3.0"
describe-wasm "^0.1.1"
toml "^2.3.3"

broccoli-slow-trees@^1.0.0:
Expand Down Expand Up @@ -2487,6 +2488,10 @@ depd@1.1.0, depd@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.0.tgz#e1bd82c6aab6ced965b97b88b17ed3e528ca18c3"

describe-wasm@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/describe-wasm/-/describe-wasm-0.1.1.tgz#155696dd49af699ea871a7db1c4d17d2ef32551b"

destroy@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80"
Expand Down

0 comments on commit af48783

Please sign in to comment.