From 7116e767cd465113b94d6d8b13a75f99e67daa0a Mon Sep 17 00:00:00 2001 From: Alex Hornby Date: Fri, 10 Nov 2023 19:09:43 +0000 Subject: [PATCH] fix mononoke build Makes usage of anyhow::Error::backtrace() conditional on fbcode_build. This is necessary because the cargo build of anyhow disables its backtrace features when using RUSTC_BOOTSTRAP=1 For build to work on current rustc stable 1.73+ I had to remove the #![feature(provide_any)] usage. You may need to be on rustc 1.73+ internally to import this successfully Test plan: local build with `./build/fbcode_builder/getdeps.py --allow-system-packages build --src-dir=. mononoke` github CI, done by regenerating the mononoke github actions with: `./build/fbcode_builder/getdeps.py --allow-system-packages generate-github-actions --free-up-disk --src-dir=. --output-dir=.github/workflows --job-name="Mononoke " --job-file-prefix=mononoke_ mononoke` Before, broken After, works --- .github/workflows/mononoke_linux.yml | 11 ++++++----- .github/workflows/mononoke_mac.yml | 5 ++++- eden/mononoke/git/git_types/src/lib.rs | 1 - .../megarepo_api/megarepo_error/src/lib.rs | 11 ++++++++++- eden/mononoke/mononoke_api/src/errors.rs | 14 ++++++++++++-- eden/mononoke/mononoke_api/src/lib.rs | 1 - 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/.github/workflows/mononoke_linux.yml b/.github/workflows/mononoke_linux.yml index 05cea196f08a4..6c5fd3252d479 100644 --- a/.github/workflows/mononoke_linux.yml +++ b/.github/workflows/mononoke_linux.yml @@ -10,11 +10,14 @@ on: branches: - main +permissions: + contents: read # to fetch code (actions/checkout) + jobs: build: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Show disk space at start run: df -h - name: Free up disk space @@ -25,10 +28,10 @@ jobs: run: sudo apt-get update - name: Install system deps run: sudo python3 build/fbcode_builder/getdeps.py --allow-system-packages install-system-deps --recursive mononoke + - name: Install packaging system deps + run: sudo python3 build/fbcode_builder/getdeps.py --allow-system-packages install-system-deps --recursive patchelf - name: Install Rust Stable uses: dtolnay/rust-toolchain@stable - - name: Fetch lld - run: python3 build/fbcode_builder/getdeps.py --allow-system-packages fetch --no-tests lld - name: Fetch ninja run: python3 build/fbcode_builder/getdeps.py --allow-system-packages fetch --no-tests ninja - name: Fetch cmake @@ -89,8 +92,6 @@ jobs: run: python3 build/fbcode_builder/getdeps.py --allow-system-packages fetch --no-tests fb303 - name: Fetch rust-shed run: python3 build/fbcode_builder/getdeps.py --allow-system-packages fetch --no-tests rust-shed - - name: Build lld - run: python3 build/fbcode_builder/getdeps.py --allow-system-packages build --free-up-disk --no-tests lld - name: Build ninja run: python3 build/fbcode_builder/getdeps.py --allow-system-packages build --free-up-disk --no-tests ninja - name: Build cmake diff --git a/.github/workflows/mononoke_mac.yml b/.github/workflows/mononoke_mac.yml index 9e6576a3e1b23..6acd89595964b 100644 --- a/.github/workflows/mononoke_mac.yml +++ b/.github/workflows/mononoke_mac.yml @@ -10,11 +10,14 @@ on: branches: - main +permissions: + contents: read # to fetch code (actions/checkout) + jobs: build: runs-on: macOS-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Show disk space at start run: df -h - name: Free up disk space diff --git a/eden/mononoke/git/git_types/src/lib.rs b/eden/mononoke/git/git_types/src/lib.rs index 5029636fa1733..f0ac1cecaab92 100644 --- a/eden/mononoke/git/git_types/src/lib.rs +++ b/eden/mononoke/git/git_types/src/lib.rs @@ -7,7 +7,6 @@ #![feature(error_generic_member_access)] #![feature(iterator_try_reduce)] -#![feature(provide_any)] pub mod mode; diff --git a/eden/mononoke/megarepo_api/megarepo_error/src/lib.rs b/eden/mononoke/megarepo_api/megarepo_error/src/lib.rs index 94e958da07f4f..97b3830d09006 100644 --- a/eden/mononoke/megarepo_api/megarepo_error/src/lib.rs +++ b/eden/mononoke/megarepo_api/megarepo_error/src/lib.rs @@ -6,7 +6,6 @@ */ #![feature(error_generic_member_access)] -#![feature(provide_any)] use std::backtrace::BacktraceStatus; use std::convert::Infallible; @@ -21,6 +20,9 @@ use thiserror::Error; pub mod macro_reexport { pub use anyhow::anyhow; } +// The cargo build of anyhow disables its backtrace features when using RUSTC_BOOTSTRAP=1 +#[cfg(not(fbcode_build))] +pub static DISABLED: std::backtrace::Backtrace = std::backtrace::Backtrace::disabled(); #[macro_export] macro_rules! cloneable_error { @@ -29,9 +31,15 @@ macro_rules! cloneable_error { pub struct $name(pub ::std::sync::Arc); impl $name { + #[cfg(fbcode_build)] pub fn backtrace(&self) -> &::std::backtrace::Backtrace { self.0.backtrace() } + + #[cfg(not(fbcode_build))] + pub fn backtrace(&self) -> &::std::backtrace::Backtrace { + &$crate::DISABLED + } } impl ::std::fmt::Display for $name { @@ -51,6 +59,7 @@ macro_rules! cloneable_error { Some(&**self.0) } + #[cfg(fbcode_build)] fn provide<'a>(&'a self, demand: &mut ::std::any::Demand<'a>) { demand.provide_ref::<::std::backtrace::Backtrace>(self.backtrace()); } diff --git a/eden/mononoke/mononoke_api/src/errors.rs b/eden/mononoke/mononoke_api/src/errors.rs index 772216ee85a33..6ed137f470d5a 100644 --- a/eden/mononoke/mononoke_api/src/errors.rs +++ b/eden/mononoke/mononoke_api/src/errors.rs @@ -5,7 +5,6 @@ * GNU General Public License version 2. */ -use std::any::Demand; use std::backtrace::Backtrace; use std::convert::Infallible; use std::error::Error as StdError; @@ -30,10 +29,20 @@ use crate::path::MononokePath; #[derive(Clone, Debug)] pub struct InternalError(Arc); +// The cargo build of anyhow disables its backtrace features when using RUSTC_BOOTSTRAP=1 +#[cfg(not(fbcode_build))] +static DISABLED: Backtrace = Backtrace::disabled(); + impl InternalError { + #[cfg(fbcode_build)] pub fn backtrace(&self) -> &Backtrace { self.0.backtrace() } + + #[cfg(not(fbcode_build))] + pub fn backtrace(&self) -> &Backtrace { + &DISABLED + } } impl fmt::Display for InternalError { @@ -53,7 +62,8 @@ impl StdError for InternalError { Some(&**self.0) } - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + #[cfg(fbcode_build)] + fn provide<'a>(&'a self, demand: &mut ::std::any::Demand<'a>) { demand.provide_ref::(self.backtrace()); } } diff --git a/eden/mononoke/mononoke_api/src/lib.rs b/eden/mononoke/mononoke_api/src/lib.rs index b74451c12cf46..3fe344bfd13d3 100644 --- a/eden/mononoke/mononoke_api/src/lib.rs +++ b/eden/mononoke/mononoke_api/src/lib.rs @@ -6,7 +6,6 @@ */ #![feature(error_generic_member_access)] -#![feature(provide_any)] #![feature(trait_alias)] use std::sync::Arc;