Skip to content

Commit effcea3

Browse files
committed
switch to host per bundle
1 parent 4dbc24f commit effcea3

File tree

5 files changed

+130
-121
lines changed

5 files changed

+130
-121
lines changed

.github/workflows/_release.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Build Release
2+
on:
3+
workflow_call:
4+
inputs:
5+
bundle:
6+
description: "The target bundle"
7+
required: true
8+
type: string
9+
runsOn:
10+
description: "The host to run on"
11+
required: true
12+
type: string
13+
14+
jobs:
15+
build:
16+
name: Release ${{ inputs.bundle }} binaries
17+
runs-on: ${{ inputs.runsOn }}
18+
permissions:
19+
contents: read
20+
packages: write
21+
attestations: write
22+
id-token: write
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: nixbuild/nix-quick-install-action@v30
26+
with:
27+
nix_conf: ${{ env.nix_conf }}
28+
- name: Restore and save Nix store
29+
uses: nix-community/cache-nix-action@v6
30+
with:
31+
primary-key: release-${{ runner.os }}-${{ hashFiles('Cargo.lock', '**/Cargo.toml', 'flake.nix', 'flake.lock', 'rust-toolchain.toml') }}
32+
restore-prefixes-first-match: |
33+
release-${{ runner.os }}-
34+
build-${{ runner.os }}-
35+
purge: true
36+
purge-prefixes: release-${{ runner.os }}-
37+
purge-created: 0
38+
purge-primary-key: never
39+
gc-max-store-size: 5G
40+
41+
- name: Build binaries
42+
run: nix build .#${{ inputs.bundle }}-release-bundle
43+
44+
- name: Upload release artifacts
45+
uses: softprops/action-gh-release@v2
46+
with:
47+
files: result/bin/*
48+
49+
- name: Generate artifact attestation
50+
uses: actions/attest-build-provenance@v2
51+
with:
52+
subject-path: "result/bin/*"

.github/workflows/release-bins.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build Release
2+
on:
3+
push:
4+
tags:
5+
- "v[0-9]+.[0-9]+.[0-9]+"
6+
7+
jobs:
8+
linux:
9+
name: Release Linux Binaries
10+
permissions:
11+
contents: read
12+
packages: write
13+
attestations: write
14+
id-token: write
15+
uses: ./.github/shared/release.workflow.yml
16+
with:
17+
bundle: linux
18+
runsOn: ubuntu-24.04
19+
secrets: inherit
20+
21+
windows:
22+
name: Release Windows Binaries
23+
permissions:
24+
contents: read
25+
packages: write
26+
attestations: write
27+
id-token: write
28+
uses: ./.github/workflows/_release.yml
29+
with:
30+
bundle: windows
31+
runsOn: ubuntu-24.04
32+
secrets: inherit

.github/workflows/release.yml renamed to .github/workflows/release-container.yml

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,6 @@ env:
99
IMAGE_NAME: ${{ github.repository }}
1010

1111
jobs:
12-
# Cross compile binaries for all supported platforms
13-
# TODO: x86_64-apple-darwin currently needs a fix in zig or hyper
14-
binaries:
15-
name: Release Binaries
16-
runs-on: ubuntu-24.04
17-
permissions:
18-
contents: read
19-
packages: write
20-
attestations: write
21-
id-token: write
22-
steps:
23-
- uses: actions/checkout@v4
24-
- uses: nixbuild/nix-quick-install-action@v30
25-
with:
26-
nix_conf: ${{ env.nix_conf }}
27-
- name: Restore and save Nix store
28-
uses: nix-community/cache-nix-action@v6
29-
with:
30-
primary-key: build-${{ runner.os }}-${{ hashFiles('Cargo.lock', '**/Cargo.toml', 'flake.nix', 'flake.lock', 'rust-toolchain.toml') }}
31-
restore-prefixes-first-match: build-${{ runner.os }}-
32-
# We don't want to affect the cache when building the container
33-
purge: false
34-
save: false
35-
36-
- name: Build the Binaries
37-
run: nix build .#crossBinaries
38-
39-
- name: Upload release artifacts
40-
uses: softprops/action-gh-release@v2
41-
with:
42-
files: result/bin/*
43-
44-
- name: Generate artifact attestation
45-
uses: actions/attest-build-provenance@v2
46-
with:
47-
subject-path: "result/bin/*"
48-
4912
# Build a container for x86_64 and aarch64 linux
5013
container:
5114
name: Release Container

flake.nix

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@
4646
inherit crane;
4747
toolchain = nativeToolchain;
4848
};
49+
mkReleaseBundle = platform: targets: let
50+
bundleToolchain = p:
51+
p.rust-bin.stable.latest.minimal.override {
52+
inherit targets;
53+
};
54+
apollo-mcp-cross = unstable-pkgs.callPackage ./nix/apollo-mcp.nix {
55+
inherit crane;
56+
toolchain = bundleToolchain;
57+
};
58+
in
59+
unstable-pkgs.symlinkJoin {
60+
name = "${platform}-release-bundle";
61+
paths = builtins.map (target: apollo-mcp-cross.packages.builder target) targets;
62+
};
4963

5064
# Supporting tools
5165
mcphost = pkgs.callPackage ./nix/mcphost.nix {};
@@ -98,62 +112,22 @@
98112
default = apollo-mcp;
99113
apollo-mcp = apollo-mcp-builder.packages.apollo-mcp;
100114

101-
crossBinaries = let
102-
crossTargets = [
103-
"aarch64-apple-darwin"
104-
"aarch64-unknown-linux-gnu"
105-
"aarch64-unknown-linux-musl"
106-
"x86_64-apple-darwin"
107-
"x86_64-pc-windows-msvc"
108-
"x86_64-unknown-linux-gnu"
109-
"x86_64-unknown-linux-musl"
110-
];
111-
crossToolchain = p:
112-
p.rust-bin.stable.latest.minimal.override {
113-
# Pull in the various supported targets for cross compilation
114-
targets = crossTargets;
115-
};
116-
apollo-mcp-cross = unstable-pkgs.callPackage ./nix/apollo-mcp.nix {
117-
inherit crane;
118-
toolchain = crossToolchain;
119-
};
120-
121-
# Individual builds for each supported platform
122-
linux-aarch64-gnu = apollo-mcp-cross.packages.builder "aarch64-unknown-linux-gnu";
123-
linux-aarch64-musl = apollo-mcp-cross.packages.builder "aarch64-unknown-linux-musl";
124-
linux-x86_64-gnu = apollo-mcp-cross.packages.builder "x86_64-unknown-linux-gnu";
125-
linux-x86_64-musl = apollo-mcp-cross.packages.builder "x86_64-unknown-linux-musl";
126-
linux = pkgs.runCommandLocal "linux-bundle" {} ''
127-
mkdir -p $out/bin
128-
129-
cp ${linux-aarch64-gnu}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.aarch64-unknown-linux-gnu
130-
cp ${linux-aarch64-musl}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.aarch64-unknown-linux-musl
131-
cp ${linux-x86_64-gnu}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.x86_64-unknown-linux-gnu
132-
cp ${linux-x86_64-musl}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.x86_64-unknown-linux-musl
133-
'';
134-
135-
macos-aarch64 = apollo-mcp-cross.packages.builder "aarch64-apple-darwin";
136-
macos-x86_64 = apollo-mcp-cross.packages.builder "x86_64-apple-darwin";
137-
macos = pkgs.runCommandLocal "macos-bundle" {} ''
138-
mkdir -p $out/bin
139-
${unstable-pkgs.lipo-go}/bin/lipo -create \
140-
-output $out/bin/apollo-mcp-server.macos \
141-
-arch arm64 ${macos-aarch64}/bin/apollo-mcp-server.lipo-apple-darwin
142-
# TODO: macos-x86_64 seems to cause a bad relocation error in hyper
143-
# -arch x86_64 ''${macos-x86_64}/bin/apollo-mcp-server
144-
145-
cp ${macos-aarch64}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.aarch64-apple-darwin
146-
# TODO: macos-x86_64 seems to cause a bad relocation error in hyper
147-
# cp ''${macos-aarch64}/bin/apollo-mcp-server $out/bin/apollo-mcp-server.x86_64-apple-darwin
148-
'';
149-
in
150-
unstable-pkgs.symlinkJoin {
151-
name = "apollo-mcp-cross-binaries";
152-
paths = [
153-
linux
154-
macos
155-
];
156-
};
115+
# Release bundles for each supported platform
116+
# TODO: x86_64-apple-darwin causes a zig issue and needs an upstream fix from aarch64 to x86_64
117+
darwin-release-bundle = mkReleaseBundle "darwin" [
118+
"aarch64-apple-darwin"
119+
"x86_64-apple-darwin"
120+
];
121+
linux-release-bundle = mkReleaseBundle "linux" [
122+
"aarch64-unknown-linux-gnu"
123+
"aarch64-unknown-linux-musl"
124+
"x86_64-unknown-linux-gnu"
125+
"x86_64-unknown-linux-musl"
126+
];
127+
windows-release-bundle = mkReleaseBundle "windows" [
128+
"aarch64-pc-windows-gnullvm"
129+
"x86_64-pc-windows-gnullvm"
130+
];
157131
};
158132

159133
# TODO: This does not work on macOS without cross compiling, so maybe

nix/apollo-mcp.nix

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
2+
apple-sdk,
23
cargo-zigbuild,
34
crane,
45
fetchzip,
56
lib,
67
perl,
78
pkg-config,
89
pkgs,
9-
toolchain,
10+
rename,
1011
stdenv,
12+
toolchain,
1113
zig,
1214
}: let
1315
graphqlFilter = path: _type: builtins.match ".*graphql$" path != null;
@@ -72,25 +74,6 @@ in {
7274
# Builder for apollo-mcp-server. Takes the rust target triple for specifying
7375
# the cross-compile target. Set the target to the same as the host for native builds.
7476
builder = target: let
75-
# Use the same apple-sdk as cargo-zigbuild
76-
apple-sdk = stdenv.mkDerivation {
77-
pname = "apple-sdk";
78-
version = "11.3";
79-
80-
src = fetchzip {
81-
url = "https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz";
82-
hash = "sha256-BoFWhRSHaD0j3dzDOFtGJ6DiRrdzMJhkjxztxCluFKo=";
83-
};
84-
85-
phases = ["installPhase"];
86-
installPhase = ''
87-
mkdir -p $out
88-
cp -r "$src"/* "$out"
89-
'';
90-
91-
passthru.sdkroot = "${apple-sdk}";
92-
};
93-
9477
# Patch cargo-zigbuild until they fix missing MacOS arguments in the linker
9578
cargo-zigbuild-patched = cargo-zigbuild.overrideAttrs {
9679
patches = [./cargo-zigbuild.patch];
@@ -105,14 +88,14 @@ in {
10588
# Helper for generating a command using cargo-zigbuild and other shell-expanded
10689
# env vars.
10790
mkCmd = cmd:
108-
builtins.concatStringsSep " " [
109-
"SDKROOT=${apple-sdk.sdkroot}"
110-
"CARGO_ZIGBUILD_CACHE_DIR=$TMP/.cache/cargo-zigbuild"
111-
"ZIG_LOCAL_CACHE_DIR=$TMP/.cache/zig-local"
112-
"ZIG_GLOBAL_CACHE_DIR=$TMP/.cache/zig-global"
113-
114-
"${cargo-zigbuild-patched}/bin/cargo-zigbuild ${cmd}"
115-
];
91+
builtins.concatStringsSep " " ((lib.optionals stdenv.isDarwin ["SDKROOT=${apple-sdk.sdkroot}"])
92+
++ [
93+
"CARGO_ZIGBUILD_CACHE_DIR=$TMP/.cache/cargo-zigbuild"
94+
"ZIG_LOCAL_CACHE_DIR=$TMP/.cache/zig-local"
95+
"ZIG_GLOBAL_CACHE_DIR=$TMP/.cache/zig-global"
96+
97+
"${cargo-zigbuild-patched}/bin/cargo-zigbuild ${cmd}"
98+
]);
11699
in
117100
craneLib.buildPackage (craneCommonArgs
118101
// {
@@ -136,6 +119,11 @@ in {
136119

137120
# Make sure to compile it for the specified target
138121
CARGO_BUILD_TARGET = target;
122+
123+
# Rename the binaries so that they have the architecture in the suffix
124+
postInstall = ''
125+
${rename}/bin/rename 's/$/.${target}/' $out/bin/*
126+
'';
139127
});
140128
};
141129
}

0 commit comments

Comments
 (0)