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

Add sdk version to contract meta automatically #1016

Merged
merged 13 commits into from
Jun 24, 2023
16 changes: 14 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions soroban-sdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ rust-version = "1.70"
proc-macro = true
doctest = false

[build_dependencies]
crate-git-revision = "0.0.6"

[dependencies]
soroban-spec = { workspace = true }
soroban-spec-rust = { workspace = true }
Expand Down
3 changes: 3 additions & 0 deletions soroban-sdk-macros/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn main() {
crate_git_revision::init();
}
24 changes: 24 additions & 0 deletions soroban-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,30 @@ pub fn contractimpl(metadata: TokenStream, input: TokenStream) -> TokenStream {
}
}

#[proc_macro]
pub fn contractmetasdkversion(_metadata: TokenStream) -> TokenStream {
// The following two lines assume that the soroban-sdk-macros crate always
// has the same version as the soroban-sdk, and lives in the same
// repository.
let pkg_version = env!("CARGO_PKG_VERSION");
let git_revision = env!("GIT_REVISION");
let version = format!("{pkg_version}#{git_revision}");
quote! {
// TODO:
// contractmeta!(
// // Rustc version.
// key = "rsver",
// val = #version,
// );
contractmeta!(
// Rust Soroban SDK version.
key = "rssdkver",
val = #version,
);
}
.into()
}

#[derive(Debug, FromMeta)]
struct MetadataArgs {
key: String,
Expand Down
2 changes: 2 additions & 0 deletions soroban-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ mod alloc;
fn __link_sections() {
#[link_section = "contractenvmetav0"]
static __ENV_META_XDR: [u8; env::meta::XDR.len()] = env::meta::XDR;

soroban_sdk_macros::contractmetasdkversion!();
}

// Re-exports of dependencies used by macros.
Expand Down