Skip to content

Commit

Permalink
fix: support macros for reexport case
Browse files Browse the repository at this point in the history
It fixes stored procs and other macros,
so that they are able to use locally imported tarantool.
  • Loading branch information
ftelnov authored and gmoshkin committed Aug 26, 2024
1 parent 2b78322 commit e8c145a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Use after free in `fiber::Builder::start_non_joinable` when the fiber exits without yielding.
- Incorrect, off-spec MP Ext type: caused runtime errors on some platforms.
- Panic in coio test starting from 1.80 Rust.
- Impossible to use procedural macros(like `tarantool::proc`, `tarantool::test`) through reexporting tarantool.

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion tarantool-proc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = [
]
name = "tarantool-proc"
description = "Tarantool proc macros"
version = "3.1.0"
version = "3.1.1"
edition = "2021"
license = "BSD-2-Clause"
documentation = "https://docs.rs/tarantool-proc/"
Expand Down
19 changes: 14 additions & 5 deletions tarantool-proc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use proc_macro2::{Span, TokenStream as TokenStream2};
use proc_macro_error::{proc_macro_error, SpanRange};
use quote::{quote, ToTokens};
use syn::{
parse_macro_input, punctuated::Punctuated, Attribute, AttributeArgs, DeriveInput, FnArg, Ident,
Item, ItemFn, Signature, Token,
parse_macro_input, parse_quote, punctuated::Punctuated, Attribute, AttributeArgs, DeriveInput,
FnArg, Ident, Item, ItemFn, Signature, Token,
};

// https://git.picodata.io/picodata/picodata/tarantool-module/-/merge_requests/505#note_78473
Expand All @@ -17,6 +17,10 @@ macro_rules! unwrap_or_compile_error {
};
}

fn default_tarantool_crate_path() -> syn::Path {
parse_quote! { tarantool }
}

mod test;

/// Mark a function as a test.
Expand Down Expand Up @@ -842,8 +846,13 @@ pub fn derive_encode(input: TokenStream) -> TokenStream {

// Get attribute arguments
let args: msgpack::Args = darling::FromDeriveInput::from_derive_input(&input).unwrap();
let tarantool_crate = args.tarantool.as_deref().unwrap_or("tarantool");
let tarantool_crate = Ident::new(tarantool_crate, Span::call_site()).into();
let tarantool_crate = args
.tarantool
.as_deref()
.map(syn::parse_str)
.transpose()
.unwrap()
.unwrap_or_else(default_tarantool_crate_path);

// Add a bound to every type parameter.
let generics = msgpack::add_trait_bounds(input.generics, &tarantool_crate);
Expand Down Expand Up @@ -1049,7 +1058,7 @@ struct Context {

impl Context {
fn from_args(args: AttributeArgs) -> Self {
let mut tarantool: syn::Path = syn::parse2(quote! { ::tarantool }).unwrap();
let mut tarantool: syn::Path = default_tarantool_crate_path();
let mut linkme = None;
let mut section = None;
let mut debug_tuple_needed = false;
Expand Down
4 changes: 3 additions & 1 deletion tarantool-proc/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use quote::quote;

use crate::default_tarantool_crate_path;

macro_rules! unwrap_or_compile_error {
($expr:expr) => {
match $expr {
Expand Down Expand Up @@ -66,7 +68,7 @@ struct Context {

impl Context {
fn from_args(tokens: proc_macro2::TokenStream) -> Result<Self, syn::Error> {
let mut tarantool = syn::parse_quote! { ::tarantool };
let mut tarantool = default_tarantool_crate_path();
let mut linkme = None;
let mut section = None;
let mut should_panic = syn::parse_quote! { false };
Expand Down
2 changes: 1 addition & 1 deletion tarantool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ serde_json = "1.0"
serde_bytes = "^0"
sha-1 = "0.9"
md-5 = "0.10"
tarantool-proc = { path = "../tarantool-proc", version = "3.1" }
tarantool-proc = { path = "../tarantool-proc", version = "3.1.1" }
uuid = "0.8.2"
futures = "0.3.25"
linkme = "0.3.0"
Expand Down

0 comments on commit e8c145a

Please sign in to comment.