Skip to content

Commit

Permalink
Add new import macro prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
cfredric committed Nov 10, 2021
1 parent 3325429 commit d619663
Show file tree
Hide file tree
Showing 3 changed files with 527 additions and 0 deletions.
34 changes: 34 additions & 0 deletions util/import_macro/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//rust:defs.bzl", "rust_library", "rust_proc_macro", "rust_test")

rust_proc_macro(
name = "import",
srcs = [
"import.rs",
],
deps = [
":import_internal",
# syn
],
)

rust_library(
name = "import_internal",
srcs = [
"import_internal.rs",
],
deps = [
# aho_corasick
# lazy_static
# proc_macro2
# quote
# syn
],
)

rust_test(
name = "import_internal_test",
crate = ":import_internal",
deps = [
# quickcheck
],
)
15 changes: 15 additions & 0 deletions util/import_macro/import.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use proc_macro;
use syn::parse_macro_input;

use import_internal;

// Flipping this bool allows easy switching between renaming crates and not.
const RENAME_1P_CRATES: bool = true;

#[proc_macro]
pub fn import(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as import_internal::ImportMacroInput);
import_internal::expand_imports(input, RENAME_1P_CRATES)
.unwrap_or_else(|errors| errors.into_iter().map(|e| e.into_compile_error()).collect())
.into()
}
Loading

0 comments on commit d619663

Please sign in to comment.