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

shared: support runtime variable for schema lookup #2657

Merged
merged 1 commit into from
Aug 16, 2021
Merged

shared: support runtime variable for schema lookup #2657

merged 1 commit into from
Aug 16, 2021

Conversation

UebelAndre
Copy link
Contributor

This change fixes a regression in being able to use version 0.2.75 for the Bazel wasm_bindgen rules. Bazel builds each crate in a separate sandbox and as a result, the CARGO_MANIFEST_DIR path is not consistent between use at runtime and compilation. To work around this, I'm looking for some way to control the lookup of the schema file when the build.rs script is run.

The change here allows for the wasm_bindgen_shared crate's build.rs script to allow CARGO_MANIFEST_DIR to be set at runtime to determine the location of the schema file.

@UebelAndre UebelAndre changed the title shared: support runtime configuration for schema lookup shared: support runtime variable for schema lookup Aug 15, 2021
@alexcrichton
Copy link
Contributor

Is this an env var that Cargo sets for execution as well as compile time? In that can this change to simply env::var?

@UebelAndre
Copy link
Contributor Author

Is this an env var that Cargo sets for execution as well as compile time? In that can this change to simply env::var?

Ah, I thought it wasn't but it appears it is:

wasm-bindgen % cargo build
   Compiling proc-macro2 v1.0.28
   Compiling unicode-xid v0.2.2
   Compiling log v0.4.14
   Compiling syn v1.0.74
   Compiling wasm-bindgen-shared v0.2.75 (/Users/user/wasm-bindgen/crates/shared)
   Compiling cfg-if v1.0.0
   Compiling bumpalo v3.7.0
   Compiling lazy_static v1.4.0
   Compiling wasm-bindgen v0.2.75 (/Users/user/wasm-bindgen)
   Compiling quote v1.0.9
   Compiling wasm-bindgen-backend v0.2.75 (/Users/user/wasm-bindgen/crates/backend)
   Compiling wasm-bindgen-macro-support v0.2.75 (/Users/user/wasm-bindgen/crates/macro-support)
   Compiling wasm-bindgen-macro v0.2.75 (/Users/user/wasm-bindgen/crates/macro)
    Finished dev [unoptimized + debuginfo] target(s) in 8.73s

(Tested with the following diff)

diff --git a/crates/shared/build.rs b/crates/shared/build.rs
index 8e6ea1b0..7de949af 100644
--- a/crates/shared/build.rs
+++ b/crates/shared/build.rs
@@ -22,6 +22,7 @@ fn main() {
 }

 fn set_schema_version_env_var() {
+    assert_eq!(env!("CARGO_MANIFEST_DIR").to_owned(), env::var("CARGO_MANIFEST_DIR").unwrap());
     let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").expect(
         "The `CARGO_MANIFEST_DIR` environment variable is needed to locate the schema file",
     );

@alexcrichton alexcrichton merged commit f4efb2c into rustwasm:master Aug 16, 2021
@alexcrichton
Copy link
Contributor

Ok, thanks!

@UebelAndre UebelAndre deleted the bazel branch August 16, 2021 15:25
@UebelAndre
Copy link
Contributor Author

Thanks @alexcrichton! What's the release cadence look like for wasm-bindgen? It'd be nice to get a 0.2.76 with this fix in 🙏

@alexcrichton
Copy link
Contributor

I generally just release when requested, I'll try to get around to it this week.

@alexcrichton
Copy link
Contributor

Ok I've published 0.2.76 now

@UebelAndre
Copy link
Contributor Author

Thank you so much! And extra thanks for all the amazing work you've done. You're an inspiration to say the least 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants