Skip to content

Commit

Permalink
fix: infer link libraries from target env
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwalker committed Aug 10, 2024
1 parent 25578d5 commit d028575
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions midenc-compile/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)]
Expand Down
15 changes: 11 additions & 4 deletions midenc-session/src/libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl FromStr for LibraryKind {

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"mast" => Ok(Self::Mast),
"mast" | "masl" => Ok(Self::Mast),
"masm" => Ok(Self::Masm),
_ => Err(()),
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
))
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/src/compiler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ fn dummy_session(flags: &[&str]) -> Rc<Session> {
}

/// Create a default session for testing
pub fn default_session<S, I>(inputs: I, extra_flags: &[S]) -> Rc<Session>
pub fn default_session<S, I>(inputs: I, argv: &[S]) -> Rc<Session>
where
I: IntoIterator<Item = InputFile>,
S: AsRef<str>,
Expand All @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions tools/cargo-miden/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?;
Expand Down

0 comments on commit d028575

Please sign in to comment.