|
1 | 1 | use anyhow::Result;
|
2 |
| -use scarb::core::Config; |
| 2 | +use scarb::{ |
| 3 | + compiler::{plugin::proc_macro::ProcMacroHost, CairoCompilationUnit, CompilationUnit}, |
| 4 | + core::{Config, Workspace}, |
| 5 | + ops::{self, FeaturesOpts, FeaturesSelector}, |
| 6 | +}; |
3 | 7 |
|
4 | 8 | #[tracing::instrument(skip_all, level = "info")]
|
5 |
| -pub fn run(_config: &Config) -> Result<()> { |
6 |
| - unimplemented!() |
| 9 | +pub fn run(config: &mut Config) -> Result<()> { |
| 10 | + let ws = ops::read_workspace(config.manifest_path(), config)?; |
| 11 | + let resolve = ops::resolve_workspace(&ws)?; |
| 12 | + let compilation_units = ops::generate_compilation_units( |
| 13 | + &resolve, |
| 14 | + &FeaturesOpts { |
| 15 | + features: FeaturesSelector::AllFeatures, |
| 16 | + no_default_features: false, |
| 17 | + }, |
| 18 | + true, |
| 19 | + &ws, |
| 20 | + )?; |
| 21 | + |
| 22 | + // Compile procedural macros only. |
| 23 | + for unit in &compilation_units { |
| 24 | + if let CompilationUnit::ProcMacro(_) = unit { |
| 25 | + ops::compile_unit(unit.clone(), &ws)?; |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + let mut proc_macros = ProcMacroHost::default(); |
| 30 | + |
| 31 | + // Load previously compiled procedural macros. |
| 32 | + for unit in compilation_units { |
| 33 | + if let CompilationUnit::Cairo(unit) = unit { |
| 34 | + load_plugins(unit, &ws, &mut proc_macros)?; |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | + ops::start_proc_macro_server(proc_macros) |
| 39 | +} |
| 40 | + |
| 41 | +fn load_plugins( |
| 42 | + unit: CairoCompilationUnit, |
| 43 | + ws: &Workspace<'_>, |
| 44 | + proc_macros: &mut ProcMacroHost, |
| 45 | +) -> Result<()> { |
| 46 | + for plugin_info in unit |
| 47 | + .cairo_plugins |
| 48 | + .into_iter() |
| 49 | + .filter(|plugin_info| !plugin_info.builtin) |
| 50 | + { |
| 51 | + proc_macros.register(plugin_info.package, ws.config())?; |
| 52 | + } |
| 53 | + |
| 54 | + Ok(()) |
7 | 55 | }
|
0 commit comments