Skip to content

Commit b502cf9

Browse files
authored
Cranelift: rework isle-in-source-tree functionality. (#9633)
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.
1 parent 6b67899 commit b502cf9

File tree

2 files changed

+12
-29
lines changed

2 files changed

+12
-29
lines changed

cranelift/codegen/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ souper-harvest = ["souper-ir", "souper-ir/stringify"]
128128
# Report any ISLE errors in pretty-printed style.
129129
isle-errors = ["cranelift-isle/fancy-errors"]
130130

131-
# Put ISLE generated files in isle_generated_code/, for easier
132-
# inspection, rather than inside of target/.
133-
isle-in-source-tree = []
134-
135131
# Enable tracking how long passes take in Cranelift.
136132
#
137133
# Enabled by default.

cranelift/codegen/build.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,37 +63,24 @@ fn main() {
6363

6464
println!("cargo:rerun-if-changed=build.rs");
6565

66-
let explicit_isle_dir = &crate_dir.join("isle_generated_code");
67-
#[cfg(feature = "isle-in-source-tree")]
68-
let isle_dir = explicit_isle_dir;
69-
#[cfg(not(feature = "isle-in-source-tree"))]
70-
let isle_dir = &out_dir;
71-
72-
#[cfg(feature = "isle-in-source-tree")]
73-
{
74-
std::fs::create_dir_all(isle_dir).expect("Could not create ISLE source directory");
75-
}
76-
#[cfg(not(feature = "isle-in-source-tree"))]
77-
{
78-
if explicit_isle_dir.is_dir() {
79-
eprintln!(concat!(
80-
"Error: directory isle_generated_code/ exists but is only used when\n",
81-
"`--feature isle-in-source-tree` is specified. To prevent confusion,\n",
82-
"this build script requires the directory to be removed when reverting\n",
83-
"to the usual generated code in target/. Please delete the directory and\n",
84-
"re-run this build.\n",
85-
));
86-
std::process::exit(1);
87-
}
88-
}
66+
let isle_dir = if let Ok(path) = std::env::var("ISLE_SOURCE_DIR") {
67+
// This will canonicalize any relative path in terms of the
68+
// crate root, and will take any absolute path as overriding the
69+
// `crate_dir`.
70+
crate_dir.join(&path)
71+
} else {
72+
out_dir.into()
73+
};
74+
75+
std::fs::create_dir_all(&isle_dir).expect("Could not create ISLE source directory");
8976

90-
if let Err(err) = meta::generate(&isas, &out_dir, isle_dir) {
77+
if let Err(err) = meta::generate(&isas, &out_dir, &isle_dir) {
9178
eprintln!("Error: {err}");
9279
process::exit(1);
9380
}
9481

9582
if &std::env::var("SKIP_ISLE").unwrap_or("0".to_string()) != "1" {
96-
if let Err(err) = build_isle(crate_dir, isle_dir) {
83+
if let Err(err) = build_isle(crate_dir, &isle_dir) {
9784
eprintln!("Error: {err}");
9885
process::exit(1);
9986
}

0 commit comments

Comments
 (0)