Skip to content

Commit

Permalink
linker: if support is WIP, use surgical only if explicit flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 30, 2024
1 parent a4165b3 commit 2624def
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
34 changes: 24 additions & 10 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>(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],
Expand Down Expand Up @@ -917,17 +940,8 @@ pub fn build(

let linking_strategy = if wasm_dev_backend {
LinkingStrategy::Additive
} else if matches.get_one::<String>(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
Expand Down
26 changes: 6 additions & 20 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -114,22 +114,8 @@ fn main() -> io::Result<()> {
};

let link_type = LinkType::Dylib;
let linking_strategy =
if matches.get_one::<String>(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(
Expand Down

0 comments on commit 2624def

Please sign in to comment.