Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions programs/bpf/Cargo.lock

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

1 change: 1 addition & 0 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ thiserror = "1.0"

[dev-dependencies]
rand = "0.7.3"
rustversion = "1.0.3"

[lib]
crate-type = ["lib", "cdylib"]
Expand Down
8 changes: 8 additions & 0 deletions programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ mod tests {
}
}

#[rustversion::since(1.46.0)]
#[test]
fn test_bpf_loader_same_crate() {
// Ensure that we can invoke this macro from the same crate
// where it is defined.
solana_bpf_loader_program!();
}

#[test]
#[should_panic(expected = "ExceededMaxInstructions(10)")]
fn test_bpf_loader_non_terminating_program() {
Expand Down
14 changes: 14 additions & 0 deletions programs/librapay/Cargo.lock

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

14 changes: 14 additions & 0 deletions programs/move_loader/Cargo.lock

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

4 changes: 4 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ ed25519-dalek = { version = "=1.0.0-pre.3", optional = true }
solana-crate-features = { path = "../crate-features", version = "1.2.11", optional = true }
solana-logger = { path = "../logger", version = "1.2.11", optional = true }
solana-sdk-macro = { path = "macro", version = "1.2.11" }
rustversion = "1.0.3"

[dev-dependencies]
tiny-bip39 = "0.7.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
rustc_version = "0.2"
27 changes: 27 additions & 0 deletions sdk/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extern crate rustc_version;
use rustc_version::{version_meta, Channel};

fn main() {
// Copied and adapted from
// https://github.com/Kimundi/rustc-version-rs/blob/1d692a965f4e48a8cb72e82cda953107c0d22f47/README.md#example
// Licensed under Apache-2.0 + MIT
match version_meta().unwrap().channel {
Channel::Stable => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Beta => {
println!("cargo:rustc-cfg=RUSTC_WITHOUT_SPECIALIZATION");
}
Channel::Nightly => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
}
Channel::Dev => {
println!("cargo:rustc-cfg=RUSTC_WITH_SPECIALIZATION");
// See https://github.com/solana-labs/solana/issues/11055
// We may be running the custom `rust-bpf-builder` toolchain,
// which currently needs `#![feature(proc_macro_hygiene)]` to
// be applied.
println!("cargo:rustc-cfg=RUSTC_NEEDS_PROC_MACRO_HYGIENE");
}
}
}
1 change: 1 addition & 0 deletions sdk/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bs58 = "0.3.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "extra-traits"] }
rustversion = "1.0.3"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
73 changes: 71 additions & 2 deletions sdk/macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate proc_macro;

use proc_macro::TokenStream;
use proc_macro2::Span;
use proc_macro2::{Delimiter, Span, TokenTree};
use quote::{quote, ToTokens};
use std::convert::TryFrom;
use syn::{
Expand All @@ -14,7 +14,7 @@ use syn::{
parse_macro_input,
punctuated::Punctuated,
token::Bracket,
Expr, Ident, LitByte, LitStr, Token,
Expr, Ident, LitByte, LitStr, Path, Token,
};

struct Id(proc_macro2::TokenStream);
Expand Down Expand Up @@ -63,6 +63,75 @@ impl ToTokens for Id {
}
}

#[allow(dead_code)] // `respan` may be compiled out
struct RespanInput {
to_respan: Path,
respan_using: Span,
}

impl Parse for RespanInput {
fn parse(input: ParseStream) -> Result<Self> {
let to_respan: Path = input.parse()?;
let _comma: Token![,] = input.parse()?;
let respan_tree: TokenTree = input.parse()?;
match respan_tree {
TokenTree::Group(g) if g.delimiter() == Delimiter::None => {
let ident: Ident = syn::parse2(g.stream())?;
Ok(RespanInput {
to_respan,
respan_using: ident.span(),
})
}
val => Err(syn::Error::new_spanned(
val,
"expected None-delimited group",
)),
}
}
}

/// A proc-macro which respans the tokens in its first argument (a `Path`)
/// to be resolved at the tokens of its second argument.
/// For internal use only.
///
/// There must be exactly one comma in the input,
/// which is used to separate the two arguments.
/// The second argument should be exactly one token.
///
/// For example, `respan!($crate::foo, with_span)`
/// produces the tokens `$crate::foo`, but resolved
/// at the span of `with_span`.
///
/// The input to this function should be very short -
/// its only purpose is to override the span of a token
/// sequence containing `$crate`. For all other purposes,
/// a more general proc-macro should be used.
#[rustversion::since(1.46.0)] // `Span::resolved_at` is stable in 1.46.0 and above
#[proc_macro]
pub fn respan(input: TokenStream) -> TokenStream {
// Obtain the `Path` we are going to respan, and the ident
// whose span we will be using.
let RespanInput {
to_respan,
respan_using,
} = parse_macro_input!(input as RespanInput);
// Respan all of the tokens in the `Path`
let to_respan: proc_macro2::TokenStream = to_respan
.into_token_stream()
.into_iter()
.map(|mut t| {
// Combine the location of the token with the resolution behavior of `respan_using`
// Note: `proc_macro2::Span::resolved_at` is currently gated with cfg(procmacro2_semver_exempt)
// Once this gate is removed, we will no longer need to use 'unwrap()' to call
// the underling `proc_macro::Span::resolved_at` method.
let new_span: Span = t.span().unwrap().resolved_at(respan_using.unwrap()).into();
t.set_span(new_span);
t
})
.collect();
TokenStream::from(to_respan)
}

#[proc_macro]
pub fn declare_id(input: TokenStream) -> TokenStream {
let id = parse_macro_input!(input as Id);
Expand Down
Loading