Skip to content

Commit e8c145a

Browse files
ftelnovgmoshkin
authored andcommitted
fix: support macros for reexport case
It fixes stored procs and other macros, so that they are able to use locally imported tarantool.
1 parent 2b78322 commit e8c145a

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Use after free in `fiber::Builder::start_non_joinable` when the fiber exits without yielding.
1616
- Incorrect, off-spec MP Ext type: caused runtime errors on some platforms.
1717
- Panic in coio test starting from 1.80 Rust.
18+
- Impossible to use procedural macros(like `tarantool::proc`, `tarantool::test`) through reexporting tarantool.
1819

1920
### Deprecated
2021

tarantool-proc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ authors = [
44
]
55
name = "tarantool-proc"
66
description = "Tarantool proc macros"
7-
version = "3.1.0"
7+
version = "3.1.1"
88
edition = "2021"
99
license = "BSD-2-Clause"
1010
documentation = "https://docs.rs/tarantool-proc/"

tarantool-proc/src/lib.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use proc_macro2::{Span, TokenStream as TokenStream2};
33
use proc_macro_error::{proc_macro_error, SpanRange};
44
use quote::{quote, ToTokens};
55
use syn::{
6-
parse_macro_input, punctuated::Punctuated, Attribute, AttributeArgs, DeriveInput, FnArg, Ident,
7-
Item, ItemFn, Signature, Token,
6+
parse_macro_input, parse_quote, punctuated::Punctuated, Attribute, AttributeArgs, DeriveInput,
7+
FnArg, Ident, Item, ItemFn, Signature, Token,
88
};
99

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

20+
fn default_tarantool_crate_path() -> syn::Path {
21+
parse_quote! { tarantool }
22+
}
23+
2024
mod test;
2125

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

843847
// Get attribute arguments
844848
let args: msgpack::Args = darling::FromDeriveInput::from_derive_input(&input).unwrap();
845-
let tarantool_crate = args.tarantool.as_deref().unwrap_or("tarantool");
846-
let tarantool_crate = Ident::new(tarantool_crate, Span::call_site()).into();
849+
let tarantool_crate = args
850+
.tarantool
851+
.as_deref()
852+
.map(syn::parse_str)
853+
.transpose()
854+
.unwrap()
855+
.unwrap_or_else(default_tarantool_crate_path);
847856

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

10501059
impl Context {
10511060
fn from_args(args: AttributeArgs) -> Self {
1052-
let mut tarantool: syn::Path = syn::parse2(quote! { ::tarantool }).unwrap();
1061+
let mut tarantool: syn::Path = default_tarantool_crate_path();
10531062
let mut linkme = None;
10541063
let mut section = None;
10551064
let mut debug_tuple_needed = false;

tarantool-proc/src/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use quote::quote;
22

3+
use crate::default_tarantool_crate_path;
4+
35
macro_rules! unwrap_or_compile_error {
46
($expr:expr) => {
57
match $expr {
@@ -66,7 +68,7 @@ struct Context {
6668

6769
impl Context {
6870
fn from_args(tokens: proc_macro2::TokenStream) -> Result<Self, syn::Error> {
69-
let mut tarantool = syn::parse_quote! { ::tarantool };
71+
let mut tarantool = default_tarantool_crate_path();
7072
let mut linkme = None;
7173
let mut section = None;
7274
let mut should_panic = syn::parse_quote! { false };

tarantool/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ serde_json = "1.0"
3636
serde_bytes = "^0"
3737
sha-1 = "0.9"
3838
md-5 = "0.10"
39-
tarantool-proc = { path = "../tarantool-proc", version = "3.1" }
39+
tarantool-proc = { path = "../tarantool-proc", version = "3.1.1" }
4040
uuid = "0.8.2"
4141
futures = "0.3.25"
4242
linkme = "0.3.0"

0 commit comments

Comments
 (0)