From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- build/rust/mozbuild/Cargo.toml | 11 +++++ build/rust/mozbuild/build.rs | 20 ++++++++ build/rust/mozbuild/generate_buildconfig.py | 75 +++++++++++++++++++++++++++++ build/rust/mozbuild/lib.rs | 14 ++++++ build/rust/mozbuild/moz.build | 9 ++++ 5 files changed, 129 insertions(+) create mode 100644 build/rust/mozbuild/Cargo.toml create mode 100644 build/rust/mozbuild/build.rs create mode 100644 build/rust/mozbuild/generate_buildconfig.py create mode 100644 build/rust/mozbuild/lib.rs create mode 100644 build/rust/mozbuild/moz.build (limited to 'build/rust/mozbuild') diff --git a/build/rust/mozbuild/Cargo.toml b/build/rust/mozbuild/Cargo.toml new file mode 100644 index 0000000000..e5958a05f8 --- /dev/null +++ b/build/rust/mozbuild/Cargo.toml @@ -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" diff --git a/build/rust/mozbuild/build.rs b/build/rust/mozbuild/build.rs new file mode 100644 index 0000000000..e9fb6b91b0 --- /dev/null +++ b/build/rust/mozbuild/build.rs @@ -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() + ); + } +} diff --git a/build/rust/mozbuild/generate_buildconfig.py b/build/rust/mozbuild/generate_buildconfig.py new file mode 100644 index 0000000000..255135ae81 --- /dev/null +++ b/build/rust/mozbuild/generate_buildconfig.py @@ -0,0 +1,75 @@ +# 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 string +import textwrap + +import buildconfig + + +def generate_bool(name): + value = buildconfig.substs.get(name) + return f"pub const {name}: bool = {'true' if value else 'false'};\n" + + +def escape_rust_string(value): + """escape the string into a Rust literal""" + # This could be more generous, but we're only escaping paths with it. + unescaped = string.ascii_letters + string.digits + "/$+-_~ " + result = "" + for ch in str(value): + if ch in unescaped: + result += ch + elif ch == "\r": + result += "\\r" + elif ch == "\n": + result += "\\n" + elif ch == "\\": + result += "\\\\" + elif ch == '"': + result += '\\"' + else: + result += "\\u{%x}" % ord(ch) + return '"%s"' % result + + +def generate(output): + # Write out a macro which can be used within `include!`-like methods to + # reference the topobjdir. + output.write( + textwrap.dedent( + f""" + /// Macro used to name a path in the objdir for use with macros like `include!` + #[macro_export] + macro_rules! objdir_path {{ + ($path:literal) => {{ + concat!({escape_rust_string(buildconfig.topobjdir + "/")}, $path) + }} + }} + + /// Macro used to name a path in the srcdir for use with macros like `include!` + #[macro_export] + macro_rules! srcdir_path {{ + ($path:literal) => {{ + concat!({escape_rust_string(buildconfig.topsrcdir + "/")}, $path) + }} + }} + + /// The objdir path for use in build scripts + pub const TOPOBJDIR: &str = {escape_rust_string(buildconfig.topobjdir)}; + /// The srcdir path for use in build scripts + pub const TOPSRCDIR: &str = {escape_rust_string(buildconfig.topsrcdir)}; + + """ + ) + ) + + # Finally, write out some useful booleans from the buildconfig. + 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")) diff --git a/build/rust/mozbuild/lib.rs b/build/rust/mozbuild/lib.rs new file mode 100644 index 0000000000..2fc70bcea2 --- /dev/null +++ b/build/rust/mozbuild/lib.rs @@ -0,0 +1,14 @@ +/* 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::path::Path; + +pub static TOPOBJDIR: Lazy<&'static Path> = Lazy::new(|| Path::new(config::TOPOBJDIR)); + +pub static TOPSRCDIR: Lazy<&'static Path> = Lazy::new(|| Path::new(config::TOPSRCDIR)); + +pub mod config { + include!(env!("BUILDCONFIG_RS")); +} diff --git a/build/rust/mozbuild/moz.build b/build/rust/mozbuild/moz.build new file mode 100644 index 0000000000..3cc09a7c5a --- /dev/null +++ b/build/rust/mozbuild/moz.build @@ -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" +) -- cgit v1.2.3