From d028575a7bbf6ec7f137c51d580f6df97f8281d0 Mon Sep 17 00:00:00 2001 From: Paul Schoenfelder Date: Sat, 10 Aug 2024 15:48:20 -0400 Subject: [PATCH] fix: infer link libraries from target env --- midenc-compile/src/compiler.rs | 5 +++++ midenc-session/src/libs.rs | 15 +++++++++++---- tests/integration/src/compiler_test.rs | 5 ++--- tools/cargo-miden/src/build.rs | 2 -- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/midenc-compile/src/compiler.rs b/midenc-compile/src/compiler.rs index 9ee41b72..221b5d9e 100644 --- a/midenc-compile/src/compiler.rs +++ b/midenc-compile/src/compiler.rs @@ -163,6 +163,11 @@ pub struct Compiler { long = "link-library", short = 'l', value_name = "[KIND=]NAME", + value_delimiter = ',', + default_value_ifs([ + ("target", "base", "std"), + ("target", "rollup", "std,base"), + ]), next_line_help(true), help_heading = "Linker" )] diff --git a/midenc-session/src/libs.rs b/midenc-session/src/libs.rs index 27c6745d..b47b6711 100644 --- a/midenc-session/src/libs.rs +++ b/midenc-session/src/libs.rs @@ -28,7 +28,7 @@ impl FromStr for LibraryKind { fn from_str(s: &str) -> Result { match s { - "mast" => Ok(Self::Mast), + "mast" | "masl" => Ok(Self::Mast), "masm" => Ok(Self::Masm), _ => Err(()), } @@ -60,8 +60,15 @@ impl LinkLibrary { } // Handle libraries shipped with the compiler, or via Miden crates - if self.name == "std" { - return Ok(StdLibrary::default().into()); + match self.name.as_ref() { + "std" => return Ok(StdLibrary::default().into()), + "base" => { + // TODO(pauls): Handle properly once we have miden-base-sys + return Err(Report::msg(format!( + "invalid link library 'base': miden-base-sys is unimplemented" + ))); + } + _ => (), } // Search for library among specified search paths @@ -160,7 +167,7 @@ impl clap::builder::TypedValueParser for LinkLibraryParser { Some(Box::new( [ PossibleValue::new("masm").help("A Miden Assembly project directory"), - PossibleValue::new("mast").help("A compiled MAST library file"), + PossibleValue::new("masl").help("A compiled MAST library file"), ] .into_iter(), )) diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index eefb5c02..495b577e 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -1202,7 +1202,7 @@ fn dummy_session(flags: &[&str]) -> Rc { } /// Create a default session for testing -pub fn default_session(inputs: I, extra_flags: &[S]) -> Rc +pub fn default_session(inputs: I, argv: &[S]) -> Rc where I: IntoIterator, S: AsRef, @@ -1214,8 +1214,7 @@ where reporting::set_panic_hook(); } - let mut argv = vec!["-l", "std"]; - argv.extend(extra_flags.iter().map(|flag| flag.as_ref())); + let argv = argv.into_iter().map(|arg| arg.as_ref()); let session = midenc_compile::Compiler::new_session(inputs, None, argv) // Ensure MASM outputs are generated .with_output_type(OutputType::Masm, None); diff --git a/tools/cargo-miden/src/build.rs b/tools/cargo-miden/src/build.rs index 2c356f62..0d404765 100644 --- a/tools/cargo-miden/src/build.rs +++ b/tools/cargo-miden/src/build.rs @@ -39,8 +39,6 @@ pub fn build_masm( output_file.as_os_str(), project_type.as_ref(), "--verbose".as_ref(), - "-l".as_ref(), - "std".as_ref(), ]; let session = Rc::new(Compiler::new_session([input], None, args)); midenc_compile::compile(session.clone())?;