Skip to content

Commit

Permalink
Cranelift: rework isle-in-source-tree functionality. (#9633)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cfallin authored Nov 20, 2024
1 parent 6b67899 commit b502cf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
4 changes: 0 additions & 4 deletions cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 12 additions & 25 deletions cranelift/codegen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b502cf9

Please sign in to comment.