Bug 1751331 - Use the mozbuild crate in gecko-profiler. r?gerald draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 21 Jan 2022 06:18:36 +0000
changeset 4180211 b66369605d9592002532c162e0870f1fa319aefa
parent 4180210 615c9a3b72f7b8026c5dc3884ec8f71c93e3a6fe
child 4180212 fbea6c71d0a0173269e656c904ec75afbf5f6cf3
push id771621
push userreviewbot
push dateFri, 21 Jan 2022 06:19:17 +0000
treeherdertry@fbea6c71d0a0 [default view] [failures only]
reviewersgerald
bugs1751331
milestone98.0a1
Bug 1751331 - Use the mozbuild crate in gecko-profiler. r?gerald Differential Revision: https://phabricator.services.mozilla.com/D136566 Differential Diff: PHID-DIFF-wavn72ykaawiji7m5n7d
Cargo.lock
tools/profiler/rust-api/Cargo.toml
tools/profiler/rust-api/build.rs
tools/profiler/rust-api/src/gecko_bindings/profiling_categories.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1867,16 +1867,17 @@ dependencies = [
 
 [[package]]
 name = "gecko-profiler"
 version = "0.1.0"
 dependencies = [
  "bincode",
  "bindgen",
  "lazy_static",
+ "mozbuild",
  "profiler-macros",
  "serde",
 ]
 
 [[package]]
 name = "gecko_logger"
 version = "0.1.0"
 dependencies = [
--- a/tools/profiler/rust-api/Cargo.toml
+++ b/tools/profiler/rust-api/Cargo.toml
@@ -4,17 +4,19 @@ version = "0.1.0"
 authors = ["The Mozilla Project Developers"]
 edition = "2018"
 
 [dependencies]
 profiler-macros = { path = "./macros" }
 lazy_static = "1"
 serde = { version = "1.0", features = ["derive"] }
 bincode = "1"
+mozbuild = "0.1"
 
 [build-dependencies]
 lazy_static = "1"
 bindgen = {version = "0.56", default-features = false}
+mozbuild = "0.1"
 
 [features]
 # This feature is being set by Gecko. If it's not set, all public functions and
 # structs will be no-op.
 enabled = []
--- a/tools/profiler/rust-api/build.rs
+++ b/tools/profiler/rust-api/build.rs
@@ -19,34 +19,26 @@ lazy_static! {
     static ref OUTDIR_PATH: PathBuf = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("gecko");
 }
 
 const BINDINGS_FILE: &str = "bindings.rs";
 
 lazy_static! {
     static ref BINDGEN_FLAGS: Vec<String> = {
         // Load build-specific config overrides.
-        let path = PathBuf::from(env::var_os("MOZ_TOPOBJDIR").unwrap())
-            .join("tools/profiler/rust-api/extra-bindgen-flags");
+        let path = mozbuild::TOPOBJDIR.join("tools/profiler/rust-api/extra-bindgen-flags");
         println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
         fs::read_to_string(path).expect("Failed to read extra-bindgen-flags file")
             .split_whitespace()
             .map(std::borrow::ToOwned::to_owned)
             .collect()
     };
-    static ref DISTDIR_PATH: PathBuf = {
-        let path = PathBuf::from(env::var_os("MOZ_TOPOBJDIR").unwrap());
-        if !path.is_absolute() || !path.is_dir() {
-            panic!("MOZ_TOPOBJDIR must be an absolute directory, was: {}", path.display());
-        }
-        path.join("dist")
-    };
     static ref SEARCH_PATHS: Vec<PathBuf> = vec![
-        DISTDIR_PATH.join("include"),
-        DISTDIR_PATH.join("include/nspr"),
+        mozbuild::TOPOBJDIR.join("dist/include"),
+        mozbuild::TOPOBJDIR.join("dist/include/nspr"),
     ];
 }
 
 fn search_include(name: &str) -> Option<PathBuf> {
     for path in SEARCH_PATHS.iter() {
         let file = path.join(name);
         if file.is_file() {
             return Some(file);
--- a/tools/profiler/rust-api/src/gecko_bindings/profiling_categories.rs
+++ b/tools/profiler/rust-api/src/gecko_bindings/profiling_categories.rs
@@ -3,19 +3,18 @@
 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
 
 //! This file contains the generated ProfilingCategory and ProfilingCategoryPair enums.
 //!
 //! The contents of this module are generated by
 //! `mozglue/baseprofiler/generate_profiling_categories.py`, from
 //! 'mozglue/baseprofiler/core/profiling_categories.yaml`.
 
-include!(concat!(
-    env!("MOZ_TOPOBJDIR"),
-    "/tools/profiler/rust-api/src/gecko_bindings/profiling_categories.rs"
+include!(mozbuild::objdir_path!(
+    "tools/profiler/rust-api/src/gecko_bindings/profiling_categories.rs"
 ));
 
 /// Helper macro that returns the profiling category pair from either only
 /// "category", or "category + sub category" pair. Refer to `profiling_categories.yaml`
 /// or generated `profiling_categories.rs` to see all the marker categories.
 /// This is useful to make the APIs similar to each other since
 /// `gecko_profiler_label!` API also requires the same syntax.
 ///