@@ -2,12 +2,14 @@ use anyhow::{anyhow, Result};
2
2
use cairo_lang_compiler:: db:: RootDatabase ;
3
3
use cairo_lang_compiler:: diagnostics:: DiagnosticsError ;
4
4
use indoc:: formatdoc;
5
+ use itertools:: Itertools ;
5
6
6
7
use scarb_ui:: components:: Status ;
7
8
use scarb_ui:: HumanDuration ;
8
9
9
10
use crate :: compiler:: db:: { build_scarb_root_database, has_starknet_plugin} ;
10
11
use crate :: compiler:: helpers:: build_compiler_config;
12
+ use crate :: compiler:: plugin:: proc_macro;
11
13
use crate :: compiler:: CompilationUnit ;
12
14
use crate :: core:: { PackageId , PackageName , TargetKind , Utf8PathWorkspaceExt , Workspace } ;
13
15
use crate :: ops;
@@ -59,11 +61,21 @@ where
59
61
60
62
let compilation_units = ops:: generate_compilation_units ( & resolve, ws) ?
61
63
. into_iter ( )
62
- . filter ( |cu| !opts. exclude_targets . contains ( & cu. target ( ) . kind ) )
63
64
. filter ( |cu| {
64
- opts. include_targets . is_empty ( ) || opts. include_targets . contains ( & cu. target ( ) . kind )
65
+ let is_excluded = opts. exclude_targets . contains ( & cu. target ( ) . kind ) ;
66
+ let is_included =
67
+ opts. include_targets . is_empty ( ) || opts. include_targets . contains ( & cu. target ( ) . kind ) ;
68
+ let is_selected = packages. contains ( & cu. main_package_id ) ;
69
+ let is_cairo_plugin = cu. components . first ( ) . unwrap ( ) . target . is_cairo_plugin ( ) ;
70
+ is_cairo_plugin || ( is_selected && is_included && !is_excluded)
71
+ } )
72
+ . sorted_by_key ( |cu| {
73
+ if cu. components . first ( ) . unwrap ( ) . target . is_cairo_plugin ( ) {
74
+ 0
75
+ } else {
76
+ 1
77
+ }
65
78
} )
66
- . filter ( |cu| packages. contains ( & cu. main_package_id ) )
67
79
. collect :: < Vec < _ > > ( ) ;
68
80
69
81
for unit in compilation_units {
@@ -89,22 +101,21 @@ fn compile_unit(unit: CompilationUnit, ws: &Workspace<'_>) -> Result<()> {
89
101
. ui ( )
90
102
. print ( Status :: new ( "Compiling" , & unit. name ( ) ) ) ;
91
103
92
- let mut db = build_scarb_root_database ( & unit, ws) ?;
93
-
94
- check_starknet_dependency ( & unit, ws, & db, & package_name) ;
95
-
96
- ws. config ( )
97
- . compilers ( )
98
- . compile ( unit, & mut db, ws)
99
- . map_err ( |err| {
100
- if !suppress_error ( & err) {
101
- ws. config ( ) . ui ( ) . anyhow ( & err) ;
102
- }
104
+ let result = if unit. is_cairo_plugin ( ) {
105
+ proc_macro:: compile_unit ( unit, ws)
106
+ } else {
107
+ let mut db = build_scarb_root_database ( & unit, ws) ?;
108
+ check_starknet_dependency ( & unit, ws, & db, & package_name) ;
109
+ ws. config ( ) . compilers ( ) . compile ( unit, & mut db, ws)
110
+ } ;
103
111
104
- anyhow ! ( "could not compile `{package_name}` due to previous error" )
105
- } ) ?;
112
+ result. map_err ( |err| {
113
+ if !suppress_error ( & err) {
114
+ ws. config ( ) . ui ( ) . anyhow ( & err) ;
115
+ }
106
116
107
- Ok ( ( ) )
117
+ anyhow ! ( "could not compile `{package_name}` due to previous error" )
118
+ } )
108
119
}
109
120
110
121
fn check_unit ( unit : CompilationUnit , ws : & Workspace < ' _ > ) -> Result < ( ) > {
0 commit comments