Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2024 the Deno authors
Copyright (c) 2018-2025 the Deno authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ Add a task to the _deno.json_ file in your project:
}
```

## Browser, Node.js, or older Deno support

The output is compatible in Deno 2.1+ or Deno 2.1.5+ if published to JSR (due to
a bug unfortunately).

Most browsers do not support Wasm imports yet, which this library generates. If
you want output that works in more scenarios, build with the `--inline` flag.

## Scaffold project (Optional)

To create a starter Rust crate in an `rs_lib` subfolder of your project, run:
Expand Down Expand Up @@ -42,9 +50,9 @@ console.log(add(1, 1));

## Checking output is up-to-date

It may occur that someone updates the Rust code, but forgets to build when
submitting a PR. To ensure that the output is up-to-date, you can use the
`--check` flag:
If you're checking your Wasm module into source control, it may occur that
someone updates the Rust code, but forgets to build when submitting a PR. To
ensure that the output is up-to-date, you can use the `--check` flag:

```shellsession
deno task wasmbuild --check
Expand All @@ -60,6 +68,8 @@ For example, in a GitHub action:
### CLI flags

- `--debug` - Build without optimizations.
- `--inline` - Inline the Wasm module. Useful for scenarios where you want a
build output that works in environments that don't support Wasm imports yet.
- `--project <crate_name>` / `-p <crate_name>` - Specifies the crate to build
when using a Cargo workspace.
- `--out <dir_path>` - Specifies the output directory. Defaults to `./lib`
Expand Down
23 changes: 12 additions & 11 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
"build": "deno run -A ./main.ts -p wasmbuild",
"build:bindgen-upgrade": "WASMBUILD_BINDGEN_UPGRADE=1 deno task build",
"build:lkg": "deno run -A jsr:@deno/wasmbuild@^0.15.4 -p wasmbuild",
"test": "cd tests && rm -rf lib lib_out_js_file lib_sync lib_no_cache && deno task test:main && deno task test:js-ext && deno test -A && deno task test:check",
"test": "cd tests && rm -rf lib lib_out_js_file lib_inline lib_no_cache && deno task test:main && deno task test:js-ext && deno task test:inline && deno test -A && deno task test:check",
"test:main": "cd tests && deno run -A ../main.ts -p deno_test",
"test:js-ext": "deno task test:main --js-ext mjs --out lib_out_js_file && cat tests/lib_out_js_file/deno_test.mjs > /dev/null",
"test:check": "deno task test:main --check"
"test:check": "deno task test:main --check",
"test:inline": "deno task test:main --inline --out lib_inline"
},
"imports": {
"@david/dax": "jsr:@david/dax@^0.39.2",
"@david/path": "jsr:@david/path@^0.2.0",
"@david/temp": "jsr:@david/temp@^0.1.1",
"@std/assert": "jsr:@std/assert@^0.218.2",
"@std/cli": "jsr:@std/cli@^0.218.2",
"@std/encoding": "jsr:@std/encoding@^0.218.2",
"@std/fmt": "jsr:@std/fmt@^0.218.2",
"@std/fs": "jsr:@std/fs@^0.218.2",
"@std/path": "jsr:@std/path@^0.218.2",
"@std/streams": "jsr:@std/streams@^1.0.6",
"@std/tar": "jsr:@std/tar@^0.1.2"
"@std/assert": "jsr:@std/assert@^1.0.11",
"@std/cli": "jsr:@std/cli@^1.0.11",
"@std/encoding": "jsr:@std/encoding@^1.0.6",
"@std/fmt": "jsr:@std/fmt@^1.0.4",
"@std/fs": "jsr:@std/fs@^1.0.10",
"@std/path": "jsr:@std/path@^1.0.8",
"@std/streams": "jsr:@std/streams@^1.0.8",
"@std/tar": "jsr:@std/tar@^0.1.4"
}
}
163 changes: 40 additions & 123 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/args.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2024 the Deno authors. MIT license.
// Copyright 2018-2025 the Deno authors. MIT license.

import { assertEquals } from "@std/assert";
import { type CommonBuild, parseArgs } from "./args.ts";
Expand All @@ -8,11 +8,12 @@ Deno.test("no default features", () => {
"--features",
"wasm",
"--no-default-features",
"--inline",
"--out",
"js",
]);
assertEquals(
(args as CommonBuild).cargoFlags,
["--no-default-features", "--features", "wasm"],
["--no-default-features", "--features", "wasm", "--inline"],
);
});
17 changes: 11 additions & 6 deletions lib/args.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. MIT license.
// Copyright 2018-2025 the Deno authors. MIT license.

import { parseArgs as parseFlags } from "@std/cli/parse_args";
import { parseArgs as parseFlags } from "@std/cli/parse-args";
import { Path } from "@david/path";

export type Command = NewCommand | BuildCommand | CheckCommand | HelpCommand;

Expand All @@ -12,11 +13,12 @@ export interface HelpCommand {
}

export interface CommonBuild {
outDir: string;
outDir: Path;
bindingJsFileExt: "js" | "mjs";
profile: "debug" | "release";
project: string | undefined;
isOpt: boolean;
inline: boolean;
cargoFlags: string[];
}

Expand All @@ -29,7 +31,9 @@ export interface CheckCommand extends CommonBuild {
}

export function parseArgs(rawArgs: string[]): Command {
const flags = parseFlags(rawArgs, { "--": true });
const flags = parseFlags(rawArgs, {
"--": true,
});
if (flags.help || flags.h) return { kind: "help" };
switch (flags._[0]) {
case "new":
Expand Down Expand Up @@ -57,7 +61,7 @@ export function parseArgs(rawArgs: string[]): Command {
function getCommonBuild(): CommonBuild {
if (flags.sync) {
throw new Error(
"The --sync flag is no longer supported now that Wasmbuild supports Wasm imports. Use an old version if you need it.",
"The --sync flag has been renamed to --inline.",
);
}
if (flags["no-cache"]) {
Expand All @@ -69,8 +73,9 @@ export function parseArgs(rawArgs: string[]): Command {
return {
profile: flags.debug ? "debug" : "release",
project: flags.p ?? flags.project,
inline: flags.inline,
isOpt: !(flags["skip-opt"] ?? flags.debug == "debug"),
outDir: flags.out ?? "./lib",
outDir: new Path(flags.out ?? "./lib"),
bindingJsFileExt: getBindingJsFileExt(),
cargoFlags: getCargoFlags(),
};
Expand Down
Loading
Loading