mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-27 01:20:48 +00:00
Use proc_macro::is_available() on rust 1.57+
This avoids the need for catching a panic, which is incompatible with projects using panic=abort or cg_clif.
This commit is contained in:
parent
0253a0b7cd
commit
f0b0040bf8
10
build.rs
10
build.rs
@ -33,6 +33,12 @@
|
||||
// location of a token. Enabled by procmacro2_semver_exempt or the
|
||||
// "span-locations" Cargo cfg. This is behind a cfg because tracking
|
||||
// location inside spans is a performance hit.
|
||||
//
|
||||
// "is_available"
|
||||
// Use `proc_macro::is_available()` to detect if the proc macro API is
|
||||
// available or needs to be polyfilled instead of trying to use the proc
|
||||
// macro API and catching a panic if it isn't available.
|
||||
// Enabled on Rust 1.57+
|
||||
|
||||
use std::env;
|
||||
use std::iter;
|
||||
@ -82,6 +88,10 @@ fn main() {
|
||||
println!("cargo:rustc-cfg=literal_from_str");
|
||||
}
|
||||
|
||||
if version.minor >= 57 {
|
||||
println!("cargo:rustc-cfg=is_available");
|
||||
}
|
||||
|
||||
let target = env::var("TARGET").unwrap();
|
||||
if !enable_use_proc_macro(&target) {
|
||||
return;
|
||||
|
@ -12,8 +12,16 @@ pub(crate) fn inside_proc_macro() -> bool {
|
||||
_ => {}
|
||||
}
|
||||
|
||||
INIT.call_once(initialize);
|
||||
inside_proc_macro()
|
||||
#[cfg(feature = "is_available")]
|
||||
{
|
||||
proc_macro::is_available()
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "is_available"))]
|
||||
{
|
||||
INIT.call_once(initialize);
|
||||
inside_proc_macro()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn force_fallback() {
|
||||
@ -21,7 +29,7 @@ pub(crate) fn force_fallback() {
|
||||
}
|
||||
|
||||
pub(crate) fn unforce_fallback() {
|
||||
initialize();
|
||||
WORKS.store(0, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
// Swap in a null panic hook to avoid printing "thread panicked" to stderr,
|
||||
|
Loading…
Reference in New Issue
Block a user