Skip to content

Commit

Permalink
fix mononoke build
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ahornby committed Nov 10, 2023
1 parent 317ae34 commit 7116e76
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/mononoke_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/mononoke_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion eden/mononoke/git/git_types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#![feature(error_generic_member_access)]
#![feature(iterator_try_reduce)]
#![feature(provide_any)]

pub mod mode;

Expand Down
11 changes: 10 additions & 1 deletion eden/mononoke/megarepo_api/megarepo_error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#![feature(error_generic_member_access)]
#![feature(provide_any)]

use std::backtrace::BacktraceStatus;
use std::convert::Infallible;
Expand All @@ -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 {
Expand All @@ -29,9 +31,15 @@ macro_rules! cloneable_error {
pub struct $name(pub ::std::sync::Arc<anyhow::Error>);

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 {
Expand All @@ -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());
}
Expand Down
14 changes: 12 additions & 2 deletions eden/mononoke/mononoke_api/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,10 +29,20 @@ use crate::path::MononokePath;
#[derive(Clone, Debug)]
pub struct InternalError(Arc<Error>);

// 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 {
Expand All @@ -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::<Backtrace>(self.backtrace());
}
}
Expand Down
1 change: 0 additions & 1 deletion eden/mononoke/mononoke_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

#![feature(error_generic_member_access)]
#![feature(provide_any)]
#![feature(trait_alias)]

use std::sync::Arc;
Expand Down

0 comments on commit 7116e76

Please sign in to comment.