Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through --weak-refs --reference-types flags to bindgen #937

Merged
merged 2 commits into from
Jan 14, 2023
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
10 changes: 10 additions & 0 deletions src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub fn wasm_bindgen_build(
out_dir: &Path,
out_name: &Option<String>,
disable_dts: bool,
weak_refs: bool,
reference_types: bool,
target: Target,
profile: BuildProfile,
) -> Result<(), failure::Error> {
Expand Down Expand Up @@ -48,6 +50,14 @@ pub fn wasm_bindgen_build(
.arg(out_dir)
.arg(dts_arg);

if weak_refs {
cmd.arg("--weak-refs");
}

if reference_types {
cmd.arg("--reference-types");
}

let target_arg = build_target_arg(target, &bindgen_path)?;
if supports_dash_dash_target(&bindgen_path)? {
cmd.arg("--target").arg(target_arg);
Expand Down
21 changes: 20 additions & 1 deletion src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct Build {
pub crate_data: manifest::CrateData,
pub scope: Option<String>,
pub disable_dts: bool,
pub weak_refs: bool,
pub reference_types: bool,
pub target: Target,
pub profile: BuildProfile,
pub mode: InstallMode,
Expand Down Expand Up @@ -132,6 +134,14 @@ pub struct BuildOptions {
/// this flag will disable generating this TypeScript file.
pub disable_dts: bool,

#[structopt(long = "weak-refs")]
/// Enable usage of the JS weak references proposal.
pub weak_refs: bool,

#[structopt(long = "reference-types")]
/// Enable usage of WebAssembly reference types.
pub reference_types: bool,

#[structopt(long = "target", short = "t", default_value = "bundler")]
/// Sets the target environment. [possible values: bundler, nodejs, web, no-modules]
pub target: Target,
Expand Down Expand Up @@ -173,6 +183,8 @@ impl Default for BuildOptions {
scope: None,
mode: InstallMode::default(),
disable_dts: false,
weak_refs: false,
reference_types: false,
target: Target::default(),
debug: false,
dev: false,
Expand Down Expand Up @@ -217,6 +229,8 @@ impl Build {
crate_data,
scope: build_opts.scope,
disable_dts: build_opts.disable_dts,
weak_refs: build_opts.weak_refs,
reference_types: build_opts.reference_types,
target: build_opts.target,
profile,
mode: build_opts.mode,
Expand Down Expand Up @@ -391,6 +405,8 @@ impl Build {
&self.out_dir,
&self.out_name,
self.disable_dts,
self.weak_refs,
self.reference_types,
self.target,
self.profile,
)?;
Expand All @@ -399,14 +415,17 @@ impl Build {
}

fn step_run_wasm_opt(&mut self) -> Result<(), Error> {
let args = match self
let mut args = match self
.crate_data
.configured_profile(self.profile)
.wasm_opt_args()
{
Some(args) => args,
None => return Ok(()),
};
if self.reference_types {
args.push("--enable-reference-types".into());
}
info!("executing wasm-opt with {:?}", args);
wasm_opt::run(
&self.cache,
Expand Down