Repository: denoland/deno
Pull request: ci: move generated deno_features code to out directory

https://github.com/denoland/deno/pull/32186 didn't fix the `deno_features` crate rebuilding on the CI.

Clause says it's because these files get fresh mtimes from a git checkout, which causes the issue. It recommended to put the generated code in the output directory.

Changed files:
filename: runtime/features/build.rs
patch: @@ -2,43 +2,22 @@
 
 #![allow(clippy::disallowed_methods)]
 
-use std::path::Path;
-
 mod data;
 mod structs;
 
 fn main() {
-  // only rerun if the build script or its input modules change,
-  // not when any file in the package changes (the default)
-  println!("cargo:rerun-if-changed=build.rs");
   println!("cargo:rerun-if-changed=data.rs");
   println!("cargo:rerun-if-changed=structs.rs");
 
-  let crate_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+  let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
 
   let mut js_list = String::from(
-    "// Copyright 2018-2026 the Deno authors. MIT license.
-
-/**
- * Don't modify this file manually.
- *
- * This file is auto-generated by the build script, modify `data.rs` instead.
- */
-
-export const unstableIds = {
+    "export const unstableIds = {
 ",
   );
 
   let mut rs_list = String::from(
-    "// Copyright 2018-2026 the Deno authors. MIT license.
-
-/// Don't modify this file manually.
-///
-/// This file is auto-generated by the build script, modify `data.rs` instead.
-use crate::structs::UnstableFeatureDefinition;
-use crate::structs::UnstableFeatureKind;
-
-pub static UNSTABLE_FEATURES: &[UnstableFeatureDefinition] = &[\n",
+    "pub static UNSTABLE_FEATURES: &[crate::structs::UnstableFeatureDefinition] = &[\n",
   );
 
   let mut descriptions = data::FEATURE_DESCRIPTIONS.to_vec();
@@ -47,12 +26,16 @@ pub static UNSTABLE_FEATURES: &[UnstableFeatureDefinition] = &[\n",
   for (id, feature) in descriptions.iter().enumerate() {
     let flag_name = format!("unstable-{}", feature.name);
     let feature_kind = match feature.kind {
-      structs::UnstableFeatureKind::Cli => "UnstableFeatureKind::Cli",
-      structs::UnstableFeatureKind::Runtime => "UnstableFeatureKind::Runtime",
+      structs::UnstableFeatureKind::Cli => {
+        "crate::structs::UnstableFeatureKind::Cli"
+      }
+      structs::UnstableFeatureKind::Runtime => {
+        "crate::structs::UnstableFeatureKind::Runtime"
+      }
     };
 
     rs_list += &format!(
-      r#"  UnstableFeatureDefinition {{
+      r#"  crate::structs::UnstableFeatureDefinition {{
     name: "{}",
     flag_name: "{}",
     help_text: "{}",
@@ -97,15 +80,8 @@ pub static UNSTABLE_FEATURES: &[UnstableFeatureDefinition] = &[\n",
   rs_list.push_str(&env_var_def);
   rs_list.push_str(&env_var_impl);
 
-  write_if_changed(&crate_dir.join("gen.js"), &js_list);
-  write_if_changed(&crate_dir.join("gen.rs"), &rs_list);
-}
-
-fn write_if_changed(path: &Path, new_text: &str) {
-  let current_text = std::fs::read_to_string(path).unwrap_or_default();
-  if current_text != new_text {
-    std::fs::write(path, new_text).unwrap();
-  }
+  std::fs::write(out_dir.join("gen.js"), &js_list).unwrap();
+  std::fs::write(out_dir.join("gen.rs"), &rs_list).unwrap();
 }
 
 fn camel_case(name: &str) -> String {

filename: runtime/features/gen.js
patch: @@ -1,28 +0,0 @@
-// Copyright 2018-2026 the Deno authors. MIT license.
-
-/**
- * Don't modify this file manually.
- *
- * This file is auto-generated by the build script, modify `data.rs` instead.
- */
-
-export const unstableIds = {
-  broadcastChannel: 1,
-  bundle: 2,
-  cron: 4,
-  ffi: 6,
-  fs: 7,
-  http: 8,
-  kv: 9,
-  net: 12,
-  noLegacyAbort: 13,
-  nodeGlobals: 14,
-  otel: 16,
-  process: 17,
-  rawImports: 18,
-  temporal: 21,
-  unsafeProto: 23,
-  vsock: 24,
-  webgpu: 25,
-  workerOptions: 26,
-};

filename: runtime/features/gen.rs
patch: @@ -1,246 +0,0 @@
-// Copyright 2018-2026 the Deno authors. MIT license.
-
-/// Don't modify this file manually.
-///
-/// This file is auto-generated by the build script, modify `data.rs` instead.
-use crate::structs::UnstableFeatureDefinition;
-use crate::structs::UnstableFeatureKind;
-
-pub static UNSTABLE_FEATURES: &[UnstableFeatureDefinition] = &[
-  UnstableFeatureDefinition {
-    name: "bare-node-builtins",
-    flag_name: "unstable-bare-node-builtins",
-    help_text: "Enable unstable bare node builtins feature",
-    show_in_help: true,
-    id: 0,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "broadcast-channel",
-    flag_name: "unstable-broadcast-channel",
-    help_text: "Enable unstable `BroadcastChannel` API",
-    show_in_help: false,
-    id: 1,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "bundle",
-    flag_name: "unstable-bundle",
-    help_text: "Enable unstable bundle runtime API",
-    show_in_help: true,
-    id: 2,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "byonm",
-    flag_name: "unstable-byonm",
-    help_text: "",
-    show_in_help: false,
-    id: 3,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "cron",
-    flag_name: "unstable-cron",
-    help_text: "Enable unstable `Deno.cron` API",
-    show_in_help: true,
-    id: 4,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "detect-cjs",
-    flag_name: "unstable-detect-cjs",
-    help_text: "Treats ambiguous .js, .jsx, .ts, .tsx files as CommonJS modules in more cases",
-    show_in_help: true,
-    id: 5,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "ffi",
-    flag_name: "unstable-ffi",
-    help_text: "Enable unstable FFI APIs",
-    show_in_help: false,
-    id: 6,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "fs",
-    flag_name: "unstable-fs",
-    help_text: "Enable unstable file system APIs",
-    show_in_help: false,
-    id: 7,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "http",
-    flag_name: "unstable-http",
-    help_text: "Enable unstable HTTP APIs",
-    show_in_help: false,
-    id: 8,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "kv",
-    flag_name: "unstable-kv",
-    help_text: "Enable unstable KV APIs",
-    show_in_help: true,
-    id: 9,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "lazy-dynamic-imports",
-    flag_name: "unstable-lazy-dynamic-imports",
-    help_text: "Lazily loads statically analyzable dynamic imports when not running with type checking. Warning: This may change the order of semver specifier resolution.",
-    show_in_help: true,
-    id: 10,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "lockfile-v5",
-    flag_name: "unstable-lockfile-v5",
-    help_text: "Enable unstable lockfile v5",
-    show_in_help: true,
-    id: 11,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "net",
-    flag_name: "unstable-net",
-    help_text: "enable unstable net APIs",
-    show_in_help: true,
-    id: 12,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "no-legacy-abort",
-    flag_name: "unstable-no-legacy-abort",
-    help_text: "Enable abort signal in Deno.serve without legacy behavior. This will not abort the server when the request is handled successfully.",
-    show_in_help: true,
-    id: 13,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "node-globals",
-    flag_name: "unstable-node-globals",
-    help_text: "Prefer Node.js globals over Deno globals - currently this refers to `setTimeout` and `setInterval` APIs.",
-    show_in_help: true,
-    id: 14,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "npm-lazy-caching",
-    flag_name: "unstable-npm-lazy-caching",
-    help_text: "Enable unstable lazy caching of npm dependencies, downloading them only as needed (disabled: all npm packages in package.json are installed on startup; enabled: only npm packages that are actually referenced in an import are installed",
-    show_in_help: true,
-    id: 15,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "otel",
-    flag_name: "unstable-otel",
-    help_text: "Enable unstable OpenTelemetry features",
-    show_in_help: false,
-    id: 16,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "process",
-    flag_name: "unstable-process",
-    help_text: "Enable unstable process APIs",
-    show_in_help: false,
-    id: 17,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "raw-imports",
-    flag_name: "unstable-raw-imports",
-    help_text: "Enable unstable 'bytes' and 'text' imports.",
-    show_in_help: true,
-    id: 18,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "sloppy-imports",
-    flag_name: "unstable-sloppy-imports",
-    help_text: "Enable unstable resolving of specifiers by extension probing, .js to .ts, and directory probing",
-    show_in_help: true,
-    id: 19,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "subdomain-wildcards",
-    flag_name: "unstable-subdomain-wildcards",
-    help_text: "Enable subdomain wildcards support for the `--allow-net` flag",
-    show_in_help: false,
-    id: 20,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "temporal",
-    flag_name: "unstable-temporal",
-    help_text: "Enable unstable Temporal API",
-    show_in_help: true,
-    id: 21,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "tsgo",
-    flag_name: "unstable-tsgo",
-    help_text: "Enable unstable TypeScript Go integration",
-    show_in_help: true,
-    id: 22,
-    kind: UnstableFeatureKind::Cli,
-  },
-  UnstableFeatureDefinition {
-    name: "unsafe-proto",
-    flag_name: "unstable-unsafe-proto",
-    help_text: "Enable unsafe __proto__ support. This is a security risk.",
-    show_in_help: true,
-    id: 23,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "vsock",
-    flag_name: "unstable-vsock",
-    help_text: "Enable unstable VSOCK APIs",
-    show_in_help: false,
-    id: 24,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "webgpu",
-    flag_name: "unstable-webgpu",
-    help_text: "Enable unstable WebGPU APIs",
-    show_in_help: true,
-    id: 25,
-    kind: UnstableFeatureKind::Runtime,
-  },
-  UnstableFeatureDefinition {
-    name: "worker-options",
-    flag_name: "unstable-worker-options",
-    help_text: "Enable unstable Web Worker APIs",
-    show_in_help: true,
-    id: 26,
-    kind: UnstableFeatureKind::Runtime,
-  },
-];
-pub struct UnstableEnvVarNames {
-  pub bare_node_builtins: &'static str,
-  pub lazy_dynamic_imports: &'static str,
-  pub lockfile_v5: &'static str,
-  pub npm_lazy_caching: &'static str,
-  pub raw_imports: &'static str,
-  pub sloppy_imports: &'static str,
-  pub subdomain_wildcards: &'static str,
-  pub tsgo: &'static str,
-}
-pub static UNSTABLE_ENV_VAR_NAMES: UnstableEnvVarNames = UnstableEnvVarNames {
-  bare_node_builtins: "DENO_UNSTABLE_BARE_NODE_BUILTINS",
-  lazy_dynamic_imports: "DENO_UNSTABLE_LAZY_DYNAMIC_IMPORTS",
-  lockfile_v5: "DENO_UNSTABLE_LOCKFILE_V5",
-  npm_lazy_caching: "DENO_UNSTABLE_NPM_LAZY_CACHING",
-  raw_imports: "DENO_UNSTABLE_RAW_IMPORTS",
-  sloppy_imports: "DENO_UNSTABLE_SLOPPY_IMPORTS",
-  subdomain_wildcards: "DENO_UNSTABLE_SUBDOMAIN_WILDCARDS",
-  tsgo: "DENO_UNSTABLE_TSGO",
-};

filename: runtime/features/lib.rs
patch: @@ -1,16 +1,15 @@
 // Copyright 2018-2026 the Deno authors. MIT license.
 
-mod r#gen;
 mod structs;
 
+include!(concat!(env!("OUT_DIR"), "/gen.rs"));
+
 use std::collections::BTreeSet;
 
-pub use r#gen::UNSTABLE_ENV_VAR_NAMES;
-pub use r#gen::UNSTABLE_FEATURES;
 pub use structs::UnstableFeatureKind;
 
 pub const JS_SOURCE: deno_core::FastStaticString =
-  deno_core::ascii_str_include!("./gen.js");
+  deno_core::ascii_str_include!(concat!(env!("OUT_DIR"), "/gen.js"));
 
 pub type ExitCb = Box<dyn Fn(&str, &str) + Send + Sync>;