Created
June 19, 2020 11:47
-
-
Save markbt/f748421d7c12effa8c5066791ce72d69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/Cargo.lock b/Cargo.lock | |
index 14f5916..2edea2b 100644 | |
--- a/Cargo.lock | |
+++ b/Cargo.lock | |
@@ -196,6 +196,13 @@ dependencies = [ | |
"syn", | |
] | |
+[[package]] | |
+name = "paste_test" | |
+version = "0.1.0" | |
+dependencies = [ | |
+ "paste", | |
+] | |
+ | |
[[package]] | |
name = "proc-macro-hack" | |
version = "0.5.16" | |
diff --git a/Cargo.toml b/Cargo.toml | |
index acda92a..7dded67 100644 | |
--- a/Cargo.toml | |
+++ b/Cargo.toml | |
@@ -3,4 +3,5 @@ | |
members = [ | |
"pyo3_test", | |
"rust_cpython_test", | |
-] | |
\ No newline at end of file | |
+ "paste_test", | |
+] | |
diff --git a/cargo/BUILD b/cargo/BUILD | |
index f813f18..1ca92d2 100644 | |
--- a/cargo/BUILD | |
+++ b/cargo/BUILD | |
@@ -16,3 +16,7 @@ alias( | |
name = "pyo3", | |
actual = "@raze__pyo3__0_10_1//:pyo3", | |
) | |
+alias( | |
+ name = "paste", | |
+ actual = "@raze__paste__0_1_16//:paste", | |
+) | |
diff --git a/paste_test/BUILD b/paste_test/BUILD | |
new file mode 100644 | |
index 0000000..208f830 | |
--- /dev/null | |
+++ b/paste_test/BUILD | |
@@ -0,0 +1,30 @@ | |
+package(default_visibility = ["//visibility:public"]) | |
+ | |
+load("@io_bazel_rules_rust//rust:rust.bzl", "rust_binary", "rust_library") | |
+ | |
+rust_library( | |
+ name = "lib", | |
+ srcs = ["src/lib.rs"], | |
+ #crate_type = "cdylib", | |
+ rustc_flags = [ | |
+ "-Z", | |
+ "macro-backtrace", | |
+ ], | |
+ deps = [ | |
+ "//cargo:paste", | |
+ ], | |
+) | |
+ | |
+rust_binary( | |
+ name = "use", | |
+ srcs = ["src/use.rs"], | |
+ deps = [ | |
+ ":lib", | |
+ ], | |
+) | |
+genrule( | |
+ name = "rust2py", | |
+ srcs = [":lib"], | |
+ outs = ["rust2py.so"], | |
+ cmd = "cp $< $@", | |
+) | |
diff --git a/paste_test/Cargo.toml b/paste_test/Cargo.toml | |
new file mode 100644 | |
index 0000000..961cc16 | |
--- /dev/null | |
+++ b/paste_test/Cargo.toml | |
@@ -0,0 +1,17 @@ | |
+[package] | |
+name = "paste_test" | |
+version = "0.1.0" | |
+authors = ["Mark Thomas <[email protected]>"] | |
+edition = "2018" | |
+ | |
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
+ | |
+[lib] | |
+name = "lib" | |
+ | |
+[[bin]] | |
+name = "use" | |
+path = "src/use.rs" | |
+ | |
+[dependencies.paste] | |
+version = "0.1" | |
diff --git a/paste_test/src/lib.rs b/paste_test/src/lib.rs | |
new file mode 100644 | |
index 0000000..3445e57 | |
--- /dev/null | |
+++ b/paste_test/src/lib.rs | |
@@ -0,0 +1,25 @@ | |
+ | |
+pub mod _detail { | |
+pub use paste; | |
+} | |
+ | |
+pub const OUTPUT: &str = "init!"; | |
+ | |
+#[macro_export] | |
+macro_rules! makeinit { | |
+ ( $name:ident ) => { | |
+ $crate::_detail::paste::item! { | |
+ #[no_mangle] | |
+ pub fn [< init $name >]() { | |
+ println!("{}", $crate::OUTPUT); // <-- compile failes because of this $crate | |
+ println!("{}", stringify!($name)); | |
+ } | |
+ } | |
+ }; | |
+} | |
+ | |
+makeinit! { foo } | |
+ | |
+pub fn foo() { | |
+ initfoo() | |
+} | |
diff --git a/paste_test/src/use.rs b/paste_test/src/use.rs | |
new file mode 100644 | |
index 0000000..61a72d2 | |
--- /dev/null | |
+++ b/paste_test/src/use.rs | |
@@ -0,0 +1,6 @@ | |
+ | |
+lib::makeinit! { bar } | |
+ | |
+pub fn main() { | |
+ initbar() | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment