-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit-id:aebc6424
- Loading branch information
Showing
5 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
pub use lib::*; | ||
pub use procedural_macro::*; | ||
pub use starknet_contract::*; | ||
pub use test::*; | ||
|
||
mod lib; | ||
mod procedural_macro; | ||
mod starknet_contract; | ||
mod test; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::compiler::{CompilationUnit, Compiler}; | ||
use crate::core::{TargetKind, Workspace}; | ||
use anyhow::{Context, Result}; | ||
use cairo_lang_compiler::db::RootDatabase; | ||
use std::path::Path; | ||
use std::process::Command; | ||
use tracing::trace_span; | ||
|
||
pub struct ProceduralMacroCompiler; | ||
|
||
impl Compiler for ProceduralMacroCompiler { | ||
fn target_kind(&self) -> TargetKind { | ||
TargetKind::CAIRO_PLUGIN.clone() | ||
} | ||
|
||
fn compile( | ||
&self, | ||
unit: CompilationUnit, | ||
_db: &mut RootDatabase, | ||
_ws: &Workspace<'_>, | ||
) -> Result<()> { | ||
let main_package = unit.components.first().unwrap().package.clone(); | ||
let mut cmd = Self::build_command(main_package.root()); | ||
{ | ||
let _ = trace_span!("compile_proc_macro").enter(); | ||
let status = cmd | ||
.status() | ||
.with_context(|| format!("Failed to execute {:?}", cmd))?; | ||
if !status.success() { | ||
return Err(anyhow::anyhow!( | ||
"Failed to compile procedural macro plugin: {:?}", | ||
cmd | ||
)); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl ProceduralMacroCompiler { | ||
fn build_command(cwd: impl AsRef<Path>) -> Command { | ||
let mut cmd = Command::new("cargo"); | ||
cmd.current_dir(cwd); | ||
cmd.arg("build"); | ||
cmd.arg("--release"); | ||
cmd | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters