Skip to content

Commit

Permalink
Add simple proc-macro loading test case (osx only)
Browse files Browse the repository at this point in the history
commit-id:e457ae12
  • Loading branch information
maciektr committed Feb 1, 2024
1 parent 8271c7b commit 6abcd21
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ members = [
"utils/test-for-each-example",
"xtask",
]
exclude = [
"scarb/fixtures/proc-macro-stub"
]
"resolver" = "2"

[workspace.package]
Expand Down
110 changes: 110 additions & 0 deletions scarb/fixtures/proc-macro-stub/Cargo.lock

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

13 changes: 13 additions & 0 deletions scarb/fixtures/proc-macro-stub/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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]
6 changes: 6 additions & 0 deletions scarb/fixtures/proc-macro-stub/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "proc_macro_stub"
version = "0.1.0"
edition = "2023_11"

[cairo-plugin]
11 changes: 11 additions & 0 deletions scarb/fixtures/proc-macro-stub/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}
Binary file not shown.
2 changes: 1 addition & 1 deletion scarb/src/compiler/plugin/proc_macro/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
24 changes: 24 additions & 0 deletions scarb/tests/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use assert_fs::TempDir;
use scarb_test_support::command::Scarb;
use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder};
use std::path::PathBuf;

#[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();
}

0 comments on commit 6abcd21

Please sign in to comment.