diff options
author | León Orell Valerian Liehr <me@fmease.dev> | 2024-03-16 23:28:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 23:28:46 +0100 |
commit | c00c5fec2aaee6000abd49d53949196e57294a3c (patch) | |
tree | 640c9c61e03a4bff959a338258846b6306f564f0 /compiler/rustc_metadata | |
parent | 766bdce744d531267d53ba2a3f9ffcda69fb9b17 (diff) | |
parent | 873a0f264e15f92af37f57d3bd3edf3d82faf34e (diff) |
Rollup merge of #117918 - daxpedda:wasm-c-abi-warning, r=workingjubilee
Add `wasm_c_abi` `future-incompat` lint
This is a warning that will tell users to update to `wasm-bindgen` v0.2.88, which supports spec-compliant C ABI.
The idea is to prepare for a future where Rust will switch to the spec-compliant C ABI by default; so not to break everyone's world, this warning is introduced.
Addresses #71871.
Diffstat (limited to 'compiler/rustc_metadata')
-rw-r--r-- | compiler/rustc_metadata/messages.ftl | 2 | ||||
-rw-r--r-- | compiler/rustc_metadata/src/creader.rs | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index a1c6fba4d43..f456dd09dea 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -281,6 +281,8 @@ metadata_unsupported_abi = metadata_unsupported_abi_i686 = ABI not supported by `#[link(kind = "raw-dylib")]` on i686 +metadata_wasm_c_abi = + older versions of the `wasm-bindgen` crate will be incompatible with future versions of Rust; please update to `wasm-bindgen` v0.2.88 metadata_wasm_import_form = wasm import module must be of the form `wasm_import_module = "string"` diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 72757d90e42..faa3bb7caec 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -31,8 +31,9 @@ use proc_macro::bridge::client::ProcMacro; use std::error::Error; use std::ops::Fn; use std::path::Path; +use std::str::FromStr; use std::time::Duration; -use std::{cmp, iter}; +use std::{cmp, env, iter}; /// The backend's way to give the crate store access to the metadata in a library. /// Note that it returns the raw metadata bytes stored in the library file, whether @@ -985,6 +986,44 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { } } + fn report_future_incompatible_deps(&self, krate: &ast::Crate) { + let name = self.tcx.crate_name(LOCAL_CRATE); + + if name.as_str() == "wasm_bindgen" { + let major = env::var("CARGO_PKG_VERSION_MAJOR") + .ok() + .and_then(|major| u64::from_str(&major).ok()); + let minor = env::var("CARGO_PKG_VERSION_MINOR") + .ok() + .and_then(|minor| u64::from_str(&minor).ok()); + let patch = env::var("CARGO_PKG_VERSION_PATCH") + .ok() + .and_then(|patch| u64::from_str(&patch).ok()); + + match (major, minor, patch) { + // v1 or bigger is valid. + (Some(1..), _, _) => return, + // v0.3 or bigger is valid. + (Some(0), Some(3..), _) => return, + // v0.2.88 or bigger is valid. + (Some(0), Some(2), Some(88..)) => return, + // Not using Cargo. + (None, None, None) => return, + _ => (), + } + + // Make a point span rather than covering the whole file + let span = krate.spans.inner_span.shrink_to_lo(); + + self.sess.psess.buffer_lint( + lint::builtin::WASM_C_ABI, + span, + ast::CRATE_NODE_ID, + crate::fluent_generated::metadata_wasm_c_abi, + ); + } + } + pub fn postprocess(&mut self, krate: &ast::Crate) { self.inject_forced_externs(); self.inject_profiler_runtime(krate); @@ -992,6 +1031,7 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { self.inject_panic_runtime(krate); self.report_unused_deps(krate); + self.report_future_incompatible_deps(krate); info!("{:?}", CrateDump(self.cstore)); } |