From 2624def4cdc6704758883e297cbac63c03d6d4d2 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Mon, 30 Dec 2024 09:12:01 +0100 Subject: [PATCH] linker: if support is WIP, use surgical only if explicit flag --- crates/cli/src/lib.rs | 34 ++++++++++++++++++++++++---------- crates/cli/src/main.rs | 26 ++++++-------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/crates/cli/src/lib.rs b/crates/cli/src/lib.rs index 5e519a02bc..79789c92a9 100644 --- a/crates/cli/src/lib.rs +++ b/crates/cli/src/lib.rs @@ -767,6 +767,29 @@ fn nearest_match<'a>(reference: &str, options: &'a [String]) -> Option<(&'a Stri .min_by(|(_, a), (_, b)| a.cmp(b)) } +pub fn default_linking_strategy( + matches: &ArgMatches, + link_type: LinkType, + target: Target, +) -> LinkingStrategy { + let linker_support_level = roc_linker::support_level(link_type, target); + match matches.get_one::(FLAG_LINKER).map(AsRef::as_ref) { + Some("legacy") => LinkingStrategy::Legacy, + Some("surgical") => match linker_support_level { + roc_linker::SupportLevel::Full => LinkingStrategy::Surgical, + roc_linker::SupportLevel::Wip => { + println!("Warning! Using an unfinished surgical linker for target {target}"); + LinkingStrategy::Surgical + } + roc_linker::SupportLevel::None => LinkingStrategy::Legacy, + }, + _ => match linker_support_level { + roc_linker::SupportLevel::Full => LinkingStrategy::Surgical, + _ => LinkingStrategy::Legacy, + }, + } +} + pub fn build( matches: &ArgMatches, subcommands: &[String], @@ -917,17 +940,8 @@ pub fn build( let linking_strategy = if wasm_dev_backend { LinkingStrategy::Additive - } else if matches.get_one::(FLAG_LINKER).map(|s| s.as_str()) == Some("legacy") { - LinkingStrategy::Legacy } else { - match roc_linker::support_level(link_type, target) { - roc_linker::SupportLevel::Full => LinkingStrategy::Surgical, - roc_linker::SupportLevel::Wip => { - println!("Warning! Using an unfinished surgical linker for target {target}"); - LinkingStrategy::Surgical - } - roc_linker::SupportLevel::None => LinkingStrategy::Legacy, - } + default_linking_strategy(matches, link_type, target) }; // All hosts should be prebuilt, this flag keeps the rebuilding behvaiour diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index e21818cd28..a112da846b 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -1,11 +1,11 @@ //! The `roc` binary that brings together all functionality in the Roc toolset. use bumpalo::Bump; -use roc_build::link::{LinkType, LinkingStrategy}; +use roc_build::link::LinkType; use roc_build::program::{check_file, CodeGenBackend}; use roc_cli::{ - build_app, format_files, format_src, test, BuildConfig, FormatMode, CMD_BUILD, CMD_CHECK, - CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL, CMD_RUN, CMD_TEST, - CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_LINKER, FLAG_MAIN, + build_app, default_linking_strategy, format_files, format_src, test, BuildConfig, FormatMode, + CMD_BUILD, CMD_CHECK, CMD_DEV, CMD_DOCS, CMD_FORMAT, CMD_GLUE, CMD_PREPROCESS_HOST, CMD_REPL, + CMD_RUN, CMD_TEST, CMD_VERSION, DIRECTORY_OR_FILES, FLAG_CHECK, FLAG_DEV, FLAG_LIB, FLAG_MAIN, FLAG_MIGRATE, FLAG_NO_COLOR, FLAG_NO_HEADER, FLAG_NO_LINK, FLAG_OUTPUT, FLAG_PP_DYLIB, FLAG_PP_HOST, FLAG_PP_PLATFORM, FLAG_STDIN, FLAG_STDOUT, FLAG_TARGET, FLAG_TIME, GLUE_DIR, GLUE_SPEC, ROC_FILE, VERSION, @@ -114,22 +114,8 @@ fn main() -> io::Result<()> { }; let link_type = LinkType::Dylib; - let linking_strategy = - if matches.get_one::(FLAG_LINKER).map(|s| s.as_str()) == Some("legacy") { - LinkingStrategy::Legacy - } else { - let target = Triple::host().into(); - match roc_linker::support_level(link_type, target) { - roc_linker::SupportLevel::Full => LinkingStrategy::Surgical, - roc_linker::SupportLevel::Wip => { - println!( - "Warning! Using an unfinished surgical linker for target {target}" - ); - LinkingStrategy::Surgical - } - roc_linker::SupportLevel::None => LinkingStrategy::Legacy, - } - }; + let target = Triple::host().into(); + let linking_strategy = default_linking_strategy(matches, link_type, target); if !output_path.exists() || output_path.is_dir() { roc_glue::generate(