@@ -13,6 +13,13 @@ struct Args {
1313
1414 #[ arg( short, long) ]
1515 output_dir : PathBuf ,
16+
17+ #[ arg( short, long) ]
18+ manifest_path : Option < PathBuf > ,
19+
20+ /// Target triple to build for (optional)
21+ #[ arg( long) ]
22+ target : Option < String > ,
1623}
1724
1825fn main ( ) {
@@ -25,24 +32,41 @@ fn main() {
2532 // Logging arguments
2633 info ! ( "Generating metadata for program at: {}" , args. crate_path. display( ) ) ;
2734 info ! ( "Output dir: {}" , args. output_dir. display( ) ) ;
35+ if let Some ( ref manifest_path) = args. manifest_path {
36+ info ! ( "Manifest path: {}" , manifest_path. display( ) ) ;
37+ } else {
38+ info ! ( "Using default manifest (no manifest path provided)" ) ;
39+ }
2840
2941 // Create a temp crate for the metadata generation
3042 let temp_dir = tempfile:: tempdir ( ) . expect ( "Failed to create temp directory" ) ;
3143 let temp_crate_path = temp_dir. path ( ) ;
3244 fs:: create_dir_all ( temp_crate_path) . expect ( "Failed to create `temp_crate` directory" ) ;
3345 info ! ( "Temp crate path: {}" , temp_crate_path. display( ) ) ;
3446
35- // Extract features section from the original manifest
36- let original_manifest_content =
37- std:: fs:: read_to_string ( args. crate_path . join ( "Cargo.toml" ) ) . expect ( "Failed to read original Cargo.toml" ) ;
38- let optional_features = pvq_program_metadata_gen:: extract_features ( & original_manifest_content)
39- . expect ( "Failed to extract features section from the original Cargo.toml" ) ;
40- debug ! ( "Features section: {:?}" , optional_features) ;
47+ // Read or create the manifest content
48+ let ( manifest_content, optional_features) = if let Some ( ref manifest_path) = args. manifest_path {
49+ // Read the manifest from the provided manifest path
50+ let content = std:: fs:: read_to_string ( manifest_path)
51+ . unwrap_or_else ( |_| panic ! ( "Failed to read manifest file: {}" , manifest_path. display( ) ) ) ;
52+ debug ! ( "Manifest content: {}" , content) ;
53+
54+ // Extract features section from the manifest for active features determination
55+ let features = pvq_program_metadata_gen:: extract_features ( & content)
56+ . expect ( "Failed to extract features section from the manifest" ) ;
57+ debug ! ( "Features section: {:?}" , features) ;
4158
42- // Create Cargo.toml with features from the original crate
43- let manifest = pvq_program_metadata_gen:: create_manifest ( optional_features. as_ref ( ) ) ;
44- debug ! ( "Manifest: {}" , manifest) ;
45- std:: fs:: write ( temp_crate_path. join ( "Cargo.toml" ) , manifest) . expect ( "Failed to write Cargo.toml" ) ;
59+ ( content, features)
60+ } else {
61+ // Use the default manifest from create_manifest
62+ let content = pvq_program_metadata_gen:: create_manifest ( None ) ;
63+ debug ! ( "Generated default manifest content: {}" , content) ;
64+ ( content, None )
65+ } ;
66+
67+ // Copy the manifest to temp directory
68+ std:: fs:: write ( temp_crate_path. join ( "Cargo.toml" ) , & manifest_content)
69+ . expect ( "Failed to write Cargo.toml to temp directory" ) ;
4670
4771 // Add active features to the cargo command
4872 let active_features = pvq_program_metadata_gen:: get_active_features ( optional_features. as_ref ( ) )
@@ -66,11 +90,20 @@ fn main() {
6690 fs:: write ( temp_crate_path. join ( "src/main.rs" ) , metadata_gen_src. to_string ( ) )
6791 . expect ( "Failed to write metadata generator source code" ) ;
6892
69- // Compile and run the metadata generator in one step
7093 let mut cargo_cmd = Command :: new ( "cargo" ) ;
7194 cargo_cmd. current_dir ( temp_crate_path) . args ( [ "run" ] ) ;
72- for feature in active_features {
73- cargo_cmd. arg ( "--features" ) . arg ( feature) ;
95+
96+ // Add target if specified
97+ if let Some ( ref target) = args. target {
98+ info ! ( "Using explicit target: {}" , target) ;
99+ cargo_cmd. arg ( "--target" ) . arg ( target) ;
100+ }
101+
102+ if !active_features. is_empty ( ) {
103+ cargo_cmd. arg ( "--features" ) ;
104+ for feature in active_features {
105+ cargo_cmd. arg ( feature) ;
106+ }
74107 }
75108 info ! ( "Compiling and running metadata generator..." ) ;
76109 let status = cargo_cmd. status ( ) . expect ( "Failed to run metadata generator" ) ;
0 commit comments