From 4f7e36639472f067b3e19a40236055e9a2192677 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 20 Nov 2024 09:16:34 -0800 Subject: [PATCH] Cranelift: rework isle-in-source-tree functionality. Per #9625 and #9588, a downstream user of Cranelift was misusing the `isle-in-source-tree` feature, enabling it indiscriminately even in published crates (wasmerio/wasmer#5202). This went against the intent of the feature, to be a way for local developers to observe the generated source. As such, it ran afoul of some safety checks for that purpose, and also polluted users' Cargo caches in a way that we cannot now fix except in future releases. The best we can do is probably to take away features that are liable to be misused. Following discussion in today's Cranelift weekly meeting, we decided to provide this functionality under an environment variable instead. This allows folks who know what they're doing to get the same behavior, but does not expose a feature to crate users. Fixes #9625. --- cranelift/codegen/Cargo.toml | 4 ---- cranelift/codegen/build.rs | 37 ++++++++++++------------------------ 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/cranelift/codegen/Cargo.toml b/cranelift/codegen/Cargo.toml index 05a54e8a6d49..c8fa87090860 100644 --- a/cranelift/codegen/Cargo.toml +++ b/cranelift/codegen/Cargo.toml @@ -128,10 +128,6 @@ souper-harvest = ["souper-ir", "souper-ir/stringify"] # Report any ISLE errors in pretty-printed style. isle-errors = ["cranelift-isle/fancy-errors"] -# Put ISLE generated files in isle_generated_code/, for easier -# inspection, rather than inside of target/. -isle-in-source-tree = [] - # Enable tracking how long passes take in Cranelift. # # Enabled by default. diff --git a/cranelift/codegen/build.rs b/cranelift/codegen/build.rs index 9d4ff1b241b3..2cbf2c9e5128 100644 --- a/cranelift/codegen/build.rs +++ b/cranelift/codegen/build.rs @@ -63,37 +63,24 @@ fn main() { println!("cargo:rerun-if-changed=build.rs"); - let explicit_isle_dir = &crate_dir.join("isle_generated_code"); - #[cfg(feature = "isle-in-source-tree")] - let isle_dir = explicit_isle_dir; - #[cfg(not(feature = "isle-in-source-tree"))] - let isle_dir = &out_dir; - - #[cfg(feature = "isle-in-source-tree")] - { - std::fs::create_dir_all(isle_dir).expect("Could not create ISLE source directory"); - } - #[cfg(not(feature = "isle-in-source-tree"))] - { - if explicit_isle_dir.is_dir() { - eprintln!(concat!( - "Error: directory isle_generated_code/ exists but is only used when\n", - "`--feature isle-in-source-tree` is specified. To prevent confusion,\n", - "this build script requires the directory to be removed when reverting\n", - "to the usual generated code in target/. Please delete the directory and\n", - "re-run this build.\n", - )); - std::process::exit(1); - } - } + let isle_dir = if let Ok(path) = std::env::var("ISLE_SOURCE_DIR") { + // This will canonicalize any relative path in terms of the + // crate root, and will take any absolute path as overriding the + // `crate_dir`. + crate_dir.join(&path) + } else { + out_dir.into() + }; + + std::fs::create_dir_all(&isle_dir).expect("Could not create ISLE source directory"); - if let Err(err) = meta::generate(&isas, &out_dir, isle_dir) { + if let Err(err) = meta::generate(&isas, &out_dir, &isle_dir) { eprintln!("Error: {err}"); process::exit(1); } if &std::env::var("SKIP_ISLE").unwrap_or("0".to_string()) != "1" { - if let Err(err) = build_isle(crate_dir, isle_dir) { + if let Err(err) = build_isle(crate_dir, &isle_dir) { eprintln!("Error: {err}"); process::exit(1); }