Bug 1751331 - Add a mozbuild crate that exposes some build configuration items. r=firefox-build-system-reviewers,andi

This will be used as a central point of authority rather than individual
crates figuring things out on their own.

Differential Revision: https://phabricator.services.mozilla.com/D136558
This commit is contained in:
Mike Hommey 2022-01-25 21:29:50 +00:00
Родитель 34c7734fc0
Коммит e013590cd1
8 изменённых файлов: 111 добавлений и 0 удалений

4
Cargo.lock сгенерированный
Просмотреть файл

@ -6019,3 +6019,7 @@ dependencies = [
"podio",
"time",
]
[[patch.unused]]
name = "mozbuild"
version = "0.1.0"

Просмотреть файл

@ -86,6 +86,9 @@ opt-level = 2
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" }

Просмотреть файл

@ -21,6 +21,9 @@ else:
if CONFIG["MOZ_STDCXX_COMPAT"]:
DIRS += ["unix/stdc++compat"]
if CONFIG["RUSTC"]:
DIRS += ["rust/mozbuild"]
CRAMTEST_MANIFESTS += [
"tests/cram/cram.ini",
]

Просмотреть файл

@ -0,0 +1,11 @@
[package]
name = "mozbuild"
version = "0.1.0"
edition = "2018"
license = "MPL-2.0"
[lib]
path = "lib.rs"
[dependencies]
once_cell = "1"

Просмотреть файл

@ -0,0 +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/. */
use std::path::PathBuf;
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()
);
}
}

Просмотреть файл

@ -0,0 +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 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"))

Просмотреть файл

@ -0,0 +1,41 @@
/* 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"),
);
assert!(
path.is_absolute() && path.is_dir(),
"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"));
assert!(
path.is_absolute() && path.is_dir(),
"MOZ_SRC must be an absolute directory, was: {}",
path.display()
);
path
});
pub mod config {
include!(env!("BUILDCONFIG_RS"));
}

Просмотреть файл

@ -0,0 +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/.
GeneratedFile(
"buildconfig.rs", script="generate_buildconfig.py", entry_point="generate"
)