diff --git a/Cargo.toml b/Cargo.toml index 69aa7fa25..4e587fe31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,9 @@ members = [ "utils/test-for-each-example", "xtask", ] +exclude = [ + "scarb/fixtures/proc-macro-stub" +] "resolver" = "2" [workspace.package] diff --git a/scarb/fixtures/proc-macro-stub/Cargo.lock b/scarb/fixtures/proc-macro-stub/Cargo.lock new file mode 100644 index 000000000..5954d7bd8 --- /dev/null +++ b/scarb/fixtures/proc-macro-stub/Cargo.lock @@ -0,0 +1,110 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "080e9890a082662b09c1ad45f567faeeb47f22b5fb23895fbe1e651e718e25ca" + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "libc" +version = "0.2.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" + +[[package]] +name = "proc-macro-stub" +version = "0.1.0" +dependencies = [ + "scarb-proc-macro-interface", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "scarb-proc-macro-interface" +version = "0.0.1" +dependencies = [ + "anyhow", + "libc", + "serde", + "serde_json", +] + +[[package]] +name = "serde" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.196" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.113" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/scarb/fixtures/proc-macro-stub/Cargo.toml b/scarb/fixtures/proc-macro-stub/Cargo.toml new file mode 100644 index 000000000..8d684962a --- /dev/null +++ b/scarb/fixtures/proc-macro-stub/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "proc-macro-stub" +version = "0.1.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["rlib", "cdylib"] + +[dependencies] +scarb-proc-macro-interface = { path = "../../../utils/scarb-proc-macro-interface"} + +[workspace] diff --git a/scarb/fixtures/proc-macro-stub/Scarb.toml b/scarb/fixtures/proc-macro-stub/Scarb.toml new file mode 100644 index 000000000..b1c1203d1 --- /dev/null +++ b/scarb/fixtures/proc-macro-stub/Scarb.toml @@ -0,0 +1,6 @@ +[package] +name = "proc_macro_stub" +version = "0.1.0" +edition = "2023_11" + +[cairo-plugin] diff --git a/scarb/fixtures/proc-macro-stub/src/lib.rs b/scarb/fixtures/proc-macro-stub/src/lib.rs new file mode 100644 index 000000000..3243e0a56 --- /dev/null +++ b/scarb/fixtures/proc-macro-stub/src/lib.rs @@ -0,0 +1,11 @@ +use scarb_proc_macro_interface::shared::{FfiProcMacroResult, FfiTokenStream}; + +/// Proc macro stub. +/// +/// # Safety +/// Note that token stream deserialization may fail. +#[no_mangle] +pub unsafe extern "C" fn expand(token_stream: FfiTokenStream) -> FfiProcMacroResult { + let _code = unsafe { token_stream.to_string() }; + FfiProcMacroResult::Leave +} diff --git a/scarb/fixtures/proc-macro-stub/target/release/libproc_macro_stub.dylib b/scarb/fixtures/proc-macro-stub/target/release/libproc_macro_stub.dylib new file mode 100755 index 000000000..c842069a5 Binary files /dev/null and b/scarb/fixtures/proc-macro-stub/target/release/libproc_macro_stub.dylib differ diff --git a/scarb/src/compiler/plugin/proc_macro/ffi.rs b/scarb/src/compiler/plugin/proc_macro/ffi.rs index 6527e0478..435d33b5a 100644 --- a/scarb/src/compiler/plugin/proc_macro/ffi.rs +++ b/scarb/src/compiler/plugin/proc_macro/ffi.rs @@ -83,7 +83,7 @@ impl Debug for ProcMacroInstance { } fn shared_lib_path(package: &Package) -> Utf8PathBuf { - let lib_name = format!("{}.dylib", package.id.name); + let lib_name = format!("lib{}.dylib", package.id.name); package.root().join("target").join("release").join(lib_name) } diff --git a/scarb/tests/proc_macro.rs b/scarb/tests/proc_macro.rs new file mode 100644 index 000000000..f3496bdc4 --- /dev/null +++ b/scarb/tests/proc_macro.rs @@ -0,0 +1,19 @@ +use std::path::PathBuf; +use assert_fs::TempDir; +use scarb_test_support::command::Scarb; +use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder}; + +#[test] +fn compile_simple() { + let proc_macro_stub_path =PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("fixtures/proc-macro-stub/"); + let t = TempDir::new().unwrap(); + ProjectBuilder::start().name("hello") + .dep("proc_macro_stub", Dep.path(proc_macro_stub_path.as_path().to_string_lossy().to_string())) + .build(&t); + + Scarb::quick_snapbox() + .arg("build") + .current_dir(&t) + .assert() + .success(); +}