Skip to content

Commit

Permalink
Add simple proc-macro loading test case
Browse files Browse the repository at this point in the history
commit-id:e457ae12
  • Loading branch information
maciektr committed Feb 2, 2024
1 parent 0ad4c52 commit 8db5149
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 0 deletions.
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.
35 changes: 35 additions & 0 deletions scarb/tests/proc_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use assert_fs::TempDir;
use scarb_test_support::command::Scarb;
use scarb_test_support::project_builder::{Dep, DepBuilder, ProjectBuilder};
use std::fs;
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);

let res = Scarb::quick_snapbox()
.arg("build")
.current_dir(&t)
.output()
.unwrap();
// .assert()
// .success();
dbg!(res);
dbg!(fs::read_dir(proc_macro_stub_path.join("target/release"))
.unwrap()
.into_iter()
.map(|p| p.unwrap().path().to_string_lossy().to_string())
.collect::<Vec<_>>());

panic!("Fail");
}

0 comments on commit 8db5149

Please sign in to comment.