Bug 1751331 - Add a mozbuild crate that exposes some build configuration items. r?build draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 21 Jan 2022 06:18:13 +0000
changeset 4180215 5cf7767566bdc80f148d9f1a5af5ed7bcc07f828
parent 4180214 7d452ce23a385d31044d2edb7bd000787df0a0f9
child 4180216 f2843dc4b43b5dda618a7f1b94a8b1a4c9e27243
push id771622
push userreviewbot
push dateFri, 21 Jan 2022 06:19:39 +0000
treeherdertry@9a7308358835 [default view] [failures only]
reviewersbuild
bugs1751331
milestone98.0a1
Bug 1751331 - Add a mozbuild crate that exposes some build configuration items. r?build This will be used as a central point of authority rather than individual crates figuring things out on their own. Differential Diff: PHID-DIFF-m5xwtknfk6fkjbnguafv
Cargo.lock
Cargo.toml
build/moz.build
build/rust/mozbuild/Cargo.toml
build/rust/mozbuild/build.rs
build/rust/mozbuild/generate_buildconfig.py
build/rust/mozbuild/lib.rs
build/rust/mozbuild/moz.build
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6004,8 +6004,12 @@ version = "0.4.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "36b9e08fb518a65cf7e08a1e482573eb87a2f4f8c6619316612a3c1f162fe822"
 dependencies = [
  "flate2",
  "msdos_time",
  "podio",
  "time",
 ]
+
+[[patch.unused]]
+name = "mozbuild"
+version = "0.1.0"
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -81,16 +81,19 @@ opt-level = 2
 [patch.crates-io]
 # The build system doesn't want those to be used, but they are pulled anyways (because
 # dependencies can't be disabled based on features), but remain unused. We ensure they
 # stay unused by overriding them with crates that contain enough to build the current
 # code and will fail the build in unwanted cases.
 cmake = { path = "build/rust/cmake" }
 vcpkg = { path = "build/rust/vcpkg" }
 
+# Helper crate for integration in the gecko build system.
+mozbuild = { path = "build/rust/mozbuild" }
+
 # Patch autocfg to hide rustc output. Workaround for https://github.com/cuviper/autocfg/issues/30
 autocfg = { path = "third_party/rust/autocfg" }
 
 # The following overrides point to dummy projects, as a temporary measure until this is resolved:
 # https://github.com/rust-lang/cargo/issues/6179
 js-sys = { path = "build/rust/dummy-web/js-sys" }
 slotmap = { path = "build/rust/dummy-web/slotmap" }
 wasm-bindgen = { path = "build/rust/dummy-web/wasm-bindgen" }
--- a/build/moz.build
+++ b/build/moz.build
@@ -16,16 +16,19 @@ with Files("docs/**"):
 if CONFIG["OS_ARCH"] == "WINNT":
     DIRS += ["win32"]
 else:
     DIRS += ["unix"]
 
 if CONFIG["MOZ_STDCXX_COMPAT"]:
     DIRS += ["unix/stdc++compat"]
 
+if CONFIG["RUSTC"]:
+    DIRS += ["rust/mozbuild"]
+
 CRAMTEST_MANIFESTS += [
     "tests/cram/cram.ini",
 ]
 
 DEFINES["ACCEPTED_MAR_CHANNEL_IDS"] = CONFIG["ACCEPTED_MAR_CHANNEL_IDS"]
 
 if CONFIG["MOZ_BUILD_APP"] == "browser":
     PYTHON_UNITTEST_MANIFESTS += [
copy from mozglue/static/rust/moz_asserts/Cargo.toml
copy to build/rust/mozbuild/Cargo.toml
--- a/mozglue/static/rust/moz_asserts/Cargo.toml
+++ b/build/rust/mozbuild/Cargo.toml
@@ -1,12 +1,11 @@
 [package]
-name = "moz_asserts"
+name = "mozbuild"
 version = "0.1.0"
 edition = "2018"
 license = "MPL-2.0"
 
 [lib]
 path = "lib.rs"
 
-[features]
-nightly = []
-diagnostic = []
+[dependencies]
+once_cell = "1"
copy from browser/components/newtab/content-src/components/MoreRecommendations/MoreRecommendations.jsx
copy to build/rust/mozbuild/build.rs
--- a/browser/components/newtab/content-src/components/MoreRecommendations/MoreRecommendations.jsx
+++ b/build/rust/mozbuild/build.rs
@@ -1,21 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-import React from "react";
+use std::path::PathBuf;
 
-export class MoreRecommendations extends React.PureComponent {
-  render() {
-    const { read_more_endpoint } = this.props;
-    if (read_more_endpoint) {
-      return (
-        <a
-          className="more-recommendations"
-          href={read_more_endpoint}
-          data-l10n-id="newtab-pocket-more-recommendations"
-        />
-      );
+fn main() {
+    let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
+    if let Some(topobjdir) = out_dir
+        .ancestors()
+        .find(|dir| dir.join("config.status").exists())
+    {
+        println!(
+            "cargo:rustc-env=BUILDCONFIG_RS={}",
+            topobjdir
+                .join("build/rust/mozbuild/buildconfig.rs")
+                .display()
+        );
     }
-    return null;
-  }
 }
copy from testing/xpcshell/example/moz.build
copy to build/rust/mozbuild/generate_buildconfig.py
--- a/testing/xpcshell/example/moz.build
+++ b/build/rust/mozbuild/generate_buildconfig.py
@@ -1,12 +1,20 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# This is a list of directories containing tests to run, separated by spaces.
-# Most likely, tho, you won't use more than one directory here.
-XPCSHELL_TESTS_MANIFESTS += [
-    "unit/xpcshell-with-prefs.ini",
-    "unit/xpcshell.ini",
-]
+import buildconfig
+
+
+def generate_bool(name):
+    value = buildconfig.substs.get(name)
+    return f"pub const {name}: bool = {'true' if value else 'false'};\n"
+
+
+def generate(output):
+    output.write(generate_bool("MOZ_FOLD_LIBS"))
+    output.write(generate_bool("NIGHTLY_BUILD"))
+    output.write(generate_bool("RELEASE_OR_BETA"))
+    output.write(generate_bool("EARLY_BETA_OR_EARLIER"))
+    output.write(generate_bool("MOZ_DEV_EDITION"))
+    output.write(generate_bool("MOZ_ESR"))
+    output.write(generate_bool("MOZ_DIAGNOSTIC_ASSERT_ENABLED"))
new file mode 100644
--- /dev/null
+++ b/build/rust/mozbuild/lib.rs
@@ -0,0 +1,42 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use once_cell::sync::Lazy;
+use std::env;
+use std::path::PathBuf;
+
+pub static TOPOBJDIR: Lazy<PathBuf> = Lazy::new(|| {
+    let path = PathBuf::from(
+        env::var_os("MOZ_TOPOBJDIR").expect("MOZ_TOPOBJDIR must be set in the environment"),
+    );
+    if !path.is_absolute() || !path.is_dir() {
+        panic!(
+            "MOZ_TOPOBJDIR must be an absolute directory, was: {}",
+            path.display()
+        );
+    }
+    path
+});
+
+#[macro_export]
+macro_rules! objdir_path {
+    ($path:literal) => { concat!(env!("MOZ_TOPOBJDIR"), "/", $path) }
+}
+
+pub static TOPSRCDIR: Lazy<PathBuf> = Lazy::new(|| {
+    let path = PathBuf::from(
+        env::var_os("MOZ_SRC").expect("MOZ_SRC must be set in the environment"),
+    );
+    if !path.is_absolute() || !path.is_dir() {
+        panic!(
+            "MOZ_SRC must be an absolute directory, was: {}",
+            path.display()
+        );
+    }
+    path
+});
+
+pub mod config {
+    include!(env!("BUILDCONFIG_RS"));
+}
copy from devtools/client/framework/browser-toolbox/moz.build
copy to build/rust/mozbuild/moz.build
--- a/devtools/client/framework/browser-toolbox/moz.build
+++ b/build/rust/mozbuild/moz.build
@@ -1,13 +1,9 @@
 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
-BROWSER_CHROME_MANIFESTS += [
-    "test/browser.ini",
-]
-
-DevToolsModules(
-    "Launcher.jsm",
+GeneratedFile(
+    "buildconfig.rs", script="generate_buildconfig.py", entry_point="generate"
 )