Skip to content

Commit

Permalink
Add initial support for aarch64-linux (#150)
Browse files Browse the repository at this point in the history
* Update `bake_process` to validate the platform matches the current platform

* Add `aarch64-linux` as a platform

* Update GH Actions workflow to build Brioche for aarch64-linux
  • Loading branch information
kylewlacy authored Dec 23, 2024
1 parent 1369ba1 commit 301fa9c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ jobs:
- name: x86_64-linux
runs_on: ubuntu-22.04
target: x86_64-unknown-linux-gnu
- name: aarch64-linux
runs_on: ubuntu-22.04
target: aarch64-unknown-linux-gnu
features: openssl/vendored
install_deps: |
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV
- name: x86_64-macos
runs_on: macos-14
target: x86_64-apple-darwin
Expand All @@ -83,19 +90,28 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
if: matrix.platform.install_deps
run: ${{ matrix.platform.install_deps }}
- name: Install Rust targets
run: rustup target add "$TARGET"
env:
TARGET: ${{ matrix.platform.target }}
- name: Build Brioche
run: |
cargo build \
--all \
--bin brioche \
--release \
--target="$TARGET"
extra_args=()
if [ -n "$FEATURES" ]; then
extra_args+=(--features "$FEATURES")
fi
cargo build \
--all \
--bin brioche \
--release \
--target="$TARGET" \
"${extra_args[@]}"
env:
TARGET: ${{ matrix.platform.target }}
FEATURES: ${{ matrix.platform.features }}
- name: Prepare artifact
run: |
mkdir -p "artifacts/brioche/$PLATFORM/"
Expand Down Expand Up @@ -130,6 +146,11 @@ jobs:
with:
name: brioche-x86_64-linux
path: artifacts/brioche
- name: Download artifacts (aarch64-linux)
uses: actions/download-artifact@v4
with:
name: brioche-aarch64-linux
path: artifacts/brioche
- name: Download artifacts (x86_64-macos)
uses: actions/download-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions crates/brioche-core/src/bake/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ pub async fn bake_process(
meta: &Arc<Meta>,
process: CompleteProcessRecipe,
) -> anyhow::Result<Artifact> {
let current_platform = crate::platform::current_platform();
anyhow::ensure!(
process.platform == current_platform,
"tried to bake process for platform {}, but only {current_platform} is supported",
process.platform,
);

tracing::debug!("acquiring process semaphore permit");
let _permit = brioche.process_semaphore.acquire().await;
tracing::debug!("acquired process semaphore permit");
Expand Down Expand Up @@ -1348,6 +1355,26 @@ pub fn process_rootfs_recipes(platform: crate::platform::Platform) -> ProcessRoo
}))),
});

ProcessRootfsRecipes { sh, env }
}
crate::platform::Platform::Aarch64Linux => {
let sh = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/dash_arm64_linux.tar.zstd".parse().unwrap(),
hash: crate::Hash::Sha256 { value: hex::decode("29ac173dee09ff377fd49d3451a382d79273c79780b8841c9860dfc2d4b353d2").unwrap() }
}))),
});
let env = Recipe::Unarchive(Unarchive {
archive: ArchiveFormat::Tar,
compression: CompressionFormat::Zstd,
file: Box::new(WithMeta::without_meta(Recipe::Download(DownloadRecipe {
url: "https://development-content.brioche.dev/github.com/tangramdotdev/bootstrap/2023-07-06/env_arm64_linux.tar.zstd".parse().unwrap(),
hash: crate::Hash::Sha256 { value: hex::decode("0b84d04b2768b6803aee78da8d54393ccbfe8730950b3cc305e8347fff5ad3d7").unwrap() }
}))),
});

ProcessRootfsRecipes { sh, env }
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/brioche-core/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
pub enum Platform {
#[strum(serialize = "x86_64-linux")]
X86_64Linux,
#[strum(serialize = "aarch64-linux")]
Aarch64Linux,
}

pub fn current_platform() -> Platform {
if cfg!(all(target_os = "linux", target_arch = "x86_64")) {
Platform::X86_64Linux
} else if cfg!(all(target_os = "linux", target_arch = "aarch64")) {
Platform::Aarch64Linux
} else {
unimplemented!("unsupported platform");
}
Expand Down
1 change: 1 addition & 0 deletions crates/brioche/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ clap = { version = "4.5.23", features = ["derive"] }
futures = "0.3.31"
hex = "0.4.3"
notify = "7.0.0"
openssl = { version = "0.10.68", optional = true }
reqwest = { version = "0.12.9", default-features = false, features = ["rustls-tls", "zstd", "json"] }
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
Expand Down

0 comments on commit 301fa9c

Please sign in to comment.