forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This makes a duplicate of `versioned-export-macros` to be used in build scripts in order to avoid the rules_rust bug: bazelbuild/rules_rust#2210
- Loading branch information
Showing
8 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
authors = ["The Wasmtime Project Developers"] | ||
description = "Macros for defining versioned exports in Wasmtime" | ||
edition.workspace = true | ||
license = "Apache-2.0 WITH LLVM-exception" | ||
name = "wasmtime-versioned-export-macros-build" | ||
repository = "https://github.com/bytecodealliance/wasmtime" | ||
version.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
syn = { workspace = true, features = ["full"] } | ||
quote = "1.0" | ||
proc-macro2 = "1.0" | ||
|
||
[lib] | ||
proc-macro = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! This crate defines macros to easily define and use functions with a | ||
//! versioned suffix, to facilitate using multiple versions of the same | ||
//! crate that generate assembly. | ||
use quote::ToTokens; | ||
|
||
const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
fn version(value: impl std::fmt::Display) -> String { | ||
format!("{}_{}", value, VERSION.replace('.', "_")) | ||
} | ||
|
||
fn versioned_lit_str(value: impl std::fmt::Display) -> syn::LitStr { | ||
syn::LitStr::new(version(value).as_str(), proc_macro2::Span::call_site()) | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn versioned_export( | ||
_attr: proc_macro::TokenStream, | ||
item: proc_macro::TokenStream, | ||
) -> proc_macro::TokenStream { | ||
let mut function = syn::parse_macro_input!(item as syn::ItemFn); | ||
|
||
let export_name = versioned_lit_str(&function.sig.ident); | ||
function | ||
.attrs | ||
.push(syn::parse_quote! { #[export_name = #export_name] }); | ||
|
||
function.to_token_stream().into() | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn versioned_link( | ||
_attr: proc_macro::TokenStream, | ||
item: proc_macro::TokenStream, | ||
) -> proc_macro::TokenStream { | ||
let mut function = syn::parse_macro_input!(item as syn::ForeignItemFn); | ||
|
||
let link_name = versioned_lit_str(&function.sig.ident); | ||
function | ||
.attrs | ||
.push(syn::parse_quote! { #[link_name = #link_name] }); | ||
|
||
function.to_token_stream().into() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn versioned_stringify_ident(item: proc_macro::TokenStream) -> proc_macro::TokenStream { | ||
let ident = syn::parse_macro_input!(item as syn::Ident); | ||
|
||
versioned_lit_str(ident).to_token_stream().into() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn versioned_suffix(item: proc_macro::TokenStream) -> proc_macro::TokenStream { | ||
if !item.is_empty() { | ||
return syn::Error::new( | ||
proc_macro2::Span::call_site(), | ||
"`versioned_suffix!` accepts no input", | ||
) | ||
.to_compile_error() | ||
.into(); | ||
}; | ||
|
||
versioned_lit_str("").to_token_stream().into() | ||
} |