-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Partially support building and locating wasm proc-macros #160981
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # `print=wasm-proc-macro-tuple` | ||
|
|
||
| The tracking issue for this feature is: [#160389](https://github.com/rust-lang/rust/issues/160389). | ||
|
|
||
| ------------------------ | ||
|
|
||
| This option of the `--print` flag produces the target for which wasm proc-macros should be compiled. | ||
|
|
||
| Intended to be used like this: | ||
|
|
||
| ```bash | ||
| rustc --print=wasm-proc-macro-tuple -Zunstable-options | ||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,14 +91,16 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R { | |
| } | ||
|
|
||
| /// The platform-specific library name | ||
| fn get_lib_name(name: &str, aux_type: AuxType) -> Option<String> { | ||
| fn get_lib_name(name: &str, aux_type: AuxType, wasm_proc_macros: bool) -> Option<String> { | ||
| match aux_type { | ||
| AuxType::Bin => None, | ||
| // In some cases (e.g. MUSL), we build a static | ||
| // library, rather than a dynamic library. | ||
| // In this case, the only path we can pass | ||
| // with '--extern-meta' is the '.rlib' file | ||
| AuxType::Lib => Some(format!("lib{name}.rlib")), | ||
| // FIXME maybe use `rustc --print file-names` instead? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably applies to the full match/function, not just this line, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, although for rlibs using the hard coded |
||
| AuxType::ProcMacro if wasm_proc_macros => Some(format!("{name}.wasm")), | ||
| AuxType::Dylib | AuxType::ProcMacro => Some(dylib_name(name)), | ||
| } | ||
| } | ||
|
|
@@ -1248,7 +1250,8 @@ impl<'test> TestCx<'test> { | |
| aux_name: &str, | ||
| aux_path: &str, | ||
| aux_type: AuxType| { | ||
| let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type); | ||
| let lib_name = | ||
| get_lib_name(&path_to_crate_name(aux_path), aux_type, self.config.wasm_proc_macros); | ||
| if let Some(lib_name) = lib_name { | ||
| let modifiers_and_name = match extern_modifiers { | ||
| Some(modifiers) => format!("{modifiers}:{aux_name}"), | ||
|
|
@@ -1279,7 +1282,11 @@ impl<'test> TestCx<'test> { | |
| // to `-Zcodegen-backend` when compiling the test file. | ||
| if let Some(aux_file) = &self.props.aux.codegen_backend { | ||
| let aux_type = self.build_auxiliary(aux_file, aux_dir, None); | ||
| if let Some(lib_name) = get_lib_name(aux_file.trim_end_matches(".rs"), aux_type) { | ||
| if let Some(lib_name) = get_lib_name( | ||
| aux_file.trim_end_matches(".rs"), | ||
| aux_type, | ||
| self.config.wasm_proc_macros, | ||
| ) { | ||
| let lib_path = aux_dir.join(&lib_name); | ||
| rustc.arg(format!("-Zcodegen-backend={}", lib_path)); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| error: unknown print request: `xxx` | ||
| | | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models` | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` | ||
| = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| error: unknown print request: `yyyy` | ||
| | | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models` | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` | ||
| = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| error: unknown print request: `lints` | ||
| | | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models` | ||
| = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` | ||
| = help: use `-Whelp` to print a list of lints | ||
| = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information | ||
|
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need support here for finding
.wasm?View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is indirectly called by
CStore::load_proc_macro. This function first tries to load for the host by callinglocator.for_proc_macro()before callingCStore::loadon it, and then for the wasm target by callinglocator.for_wasm_proc_macro()beforeCStore::load. For the second call, thefor_wasm_proc_macrocauses the locator to attempt to load a crate for wasm32-wasip2. This in turn causes the locator to use the.wasmsuffix for dylibs as indicated in the target spec.