Skip to content

Commit

Permalink
Proc macro server: Load ProcMacroHost
Browse files Browse the repository at this point in the history
commit-id:819109f5
  • Loading branch information
Draggu committed Nov 4, 2024
1 parent da19bcf commit c5b5dac
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
53 changes: 50 additions & 3 deletions scarb/src/bin/scarb/commands/proc_macro_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,54 @@
use anyhow::Result;
use scarb::core::Config;
use scarb::{
compiler::{plugin::proc_macro::ProcMacroHost, CairoCompilationUnit, CompilationUnit},
core::{Config, Workspace},
ops::{self, FeaturesOpts, FeaturesSelector},
};

#[tracing::instrument(skip_all, level = "info")]
pub fn run(_config: &Config) -> Result<()> {
unimplemented!()
pub fn run(config: &mut Config) -> Result<()> {
let ws = ops::read_workspace(config.manifest_path(), config)?;
let resolve = ops::resolve_workspace(&ws)?;
let compilation_units = ops::generate_compilation_units(
&resolve,
&FeaturesOpts {
features: FeaturesSelector::AllFeatures,
no_default_features: false,
},
&ws,
)?;

// Compile procedural macros only.
for unit in &compilation_units {
if let CompilationUnit::ProcMacro(_) = unit {
ops::compile_unit(unit.clone(), &ws)?;
}
}

let mut proc_macros = ProcMacroHost::default();

// Load previously compiled procedural macros.
for unit in compilation_units {
if let CompilationUnit::Cairo(unit) = unit {
load_plugins(unit, &ws, &mut proc_macros)?;
}
}

ops::start_proc_macro_server(proc_macros)
}

fn load_plugins(
unit: CairoCompilationUnit,
ws: &Workspace<'_>,
proc_macros: &mut ProcMacroHost,
) -> Result<()> {
for plugin_info in unit
.cairo_plugins
.into_iter()
.filter(|plugin_info| !plugin_info.builtin)
{
proc_macros.register(plugin_info.package, ws.config())?;
}

Ok(())
}
2 changes: 2 additions & 0 deletions scarb/src/ops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub use manifest::*;
pub use metadata::*;
pub use new::*;
pub use package::*;
pub use proc_macro_server::*;
pub use publish::*;
pub use resolve::*;
pub use scripts::*;
Expand All @@ -27,6 +28,7 @@ mod manifest;
mod metadata;
mod new;
mod package;
mod proc_macro_server;
mod publish;
mod resolve;
mod scripts;
Expand Down
6 changes: 6 additions & 0 deletions scarb/src/ops/proc_macro_server/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::compiler::plugin::proc_macro::ProcMacroHost;
use anyhow::Result;

pub fn start_proc_macro_server(proc_macros: ProcMacroHost) -> Result<()> {
unimplemented!()
}

0 comments on commit c5b5dac

Please sign in to comment.