Skip to content

Commit d7385fe

Browse files
author
Marc Jakobi
committed
build: cross-compiled binary distributions
1 parent 905dad8 commit d7385fe

3 files changed

Lines changed: 169 additions & 35 deletions

File tree

.github/workflows/cd.yml

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ permissions:
44
contents: write
55

66
on:
7+
pull_request: # TODO: remove this
78
release:
89
types: [published]
910
workflow_dispatch:
@@ -35,18 +36,18 @@ jobs:
3536
os: windows-2025
3637
- target: aarch64-apple-darwin
3738
os: macos-15
38-
# - target: aarch64-unknown-linux-gnu
39-
# os: ubuntu-22.04
40-
# - target: aarch64-unknown-linux-musl
41-
# os: ubuntu-22.04
39+
- target: aarch64-unknown-linux-gnu
40+
os: ubuntu-22.04
41+
- target: x86_64-unknown-linux-musl
42+
os: ubuntu-22.04
43+
- target: aarch64-unknown-linux-musl
44+
os: ubuntu-22.04
4245
# - target: aarch64-pc-windows-msvc
4346
# os: windows-2022
44-
# - target: x86_64-apple-darwin
45-
# os: macos-13
46-
# - target: x86_64-unknown-freebsd
47-
# os: ubuntu-22.04
48-
# - target: x86_64-unknown-linux-musl
49-
# os: ubuntu-22.04
47+
- target: x86_64-apple-darwin
48+
os: macos-15
49+
- target: x86_64-unknown-freebsd
50+
os: ubuntu-22.04
5051
fail-fast: false
5152
timeout-minutes: 120
5253
runs-on: ${{ matrix.os }}
@@ -68,27 +69,13 @@ jobs:
6869
- name: Nix devShell
6970
uses: nicknovitski/nix-develop@v1.2.1
7071
with:
71-
arguments: ".#cd"
72+
arguments: ".#cd_${{ matrix.target }}"
7273
if: "!startsWith(matrix.os, 'windows')"
7374

7475
- name: Install Rust Toolchain
7576
uses: actions-rust-lang/setup-rust-toolchain@v1
7677
if: startsWith(matrix.os, 'windows')
7778

78-
# NOTE: We cannot cross-compile yet because of dynamically linked dependencies:
79-
# - gpgme -> lgpg-error, lgpgme
80-
# - git2 -> lgit2
81-
#
82-
# - name: Setup cross toolchain
83-
# uses: taiki-e/setup-cross-toolchain-action@v1
84-
# with:
85-
# target: ${{ matrix.target }}
86-
# if: startsWith(matrix.os, 'ubuntu') && !contains(matrix.target, '-musl')
87-
#
88-
# - name: Add target via rustup
89-
# run: rustup target add ${{ matrix.target }}
90-
# if: "!endsWith(matrix.target, 'windows-msvc')"
91-
9279
- name: "Setup environment for MSVC"
9380
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> "${GITHUB_ENV}"
9481
if: endsWith(matrix.target, 'windows-msvc')

flake.lock

Lines changed: 100 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
inputs = {
1010
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
1111
crane.url = "github:ipetkov/crane";
12+
nixpkgs-cross-overlay = {
13+
url = "github:alekseysidorov/nixpkgs-cross-overlay";
14+
inputs.nixpkgs.follows = "nixpkgs";
15+
};
1216
flake-parts.url = "github:hercules-ci/flake-parts";
1317
git-hooks = {
1418
url = "github:cachix/git-hooks.nix";
@@ -67,7 +71,6 @@
6771
cargo-nextest
6872
cargo-hakari
6973
cargo-insta
70-
cargo-cross
7174
clippy
7275
taplo
7376
# Needed for integration test builds
@@ -82,16 +85,41 @@
8285
++ pkgs.lux-cli.nativeBuildInputs;
8386
};
8487

85-
mkBuildShell = pkgs':
86-
pkgs'.mkShell {
88+
mkBuildShell = {
89+
buildInputs ? [],
90+
shellHook ? "",
91+
}:
92+
pkgs.mkShell {
8793
name = "lux buildShell";
8894
buildInputs =
89-
(
90-
lib.filter
95+
buildInputs
96+
++ pkgs.lux-cli.nativeBuildInputs;
97+
inherit shellHook;
98+
};
99+
100+
mkCrossBuildShell = target: let
101+
crossSystem = {
102+
config = target;
103+
isStatic = true;
104+
useLLVM = true;
105+
};
106+
pkgsCross = import nixpkgs {
107+
localSystem = system;
108+
inherit crossSystem;
109+
overlays = [
110+
inputs.nixpkgs-cross-overlay.overlays.default
111+
];
112+
};
113+
in
114+
mkBuildShell
115+
{
116+
buildInputs =
117+
[pkgsCross.rustCrossHook]
118+
++ (lib.filter
91119
(pkg: !(lib.hasPrefix "lua" pkg.name))
92-
pkgs'.lux-cli.buildInputs
93-
)
94-
++ pkgs'.lux-cli.nativeBuildInputs;
120+
pkgsCross.lux-cli.buildInputs)
121+
++ pkgsCross.lux-cli.nativeBuildInputs;
122+
shellHook = pkgsCross.crossBashPrompt;
95123
};
96124
in rec {
97125
default = lua54;
@@ -100,7 +128,27 @@
100128
lua53 = mkDevShell [pkgs.lua5_3];
101129
lua54 = mkDevShell [pkgs.lua5_4];
102130
luajit = mkDevShell [pkgs.luajit];
103-
cd = mkBuildShell pkgs;
131+
cd =
132+
mkBuildShell
133+
{
134+
buildInputs =
135+
(lib.filter
136+
(pkg: !(lib.hasPrefix "lua" pkg.name))
137+
pkgs.lux-cli.buildInputs)
138+
++ pkgs.lux-cli.nativeBuildInputs;
139+
};
140+
cd_x86_64-unknown-linux-gnu = cd;
141+
cd_aarch64-apple-darwin = cd;
142+
cd_x86_64-unknown-linux-musl =
143+
mkCrossBuildShell "x86_64-unknown-linux-musl";
144+
cd_aarch64-unknown-linux-gnu =
145+
mkCrossBuildShell "aarch64-unknown-linux-gnu";
146+
cd_aarch64-unknown-linux-musl =
147+
mkCrossBuildShell "aarch64-unknown-linux-musl";
148+
cd_x86_64-unknown-freebsd =
149+
mkCrossBuildShell "x86_64-unknown-freebsd";
150+
cd_x86_64-apple-darwin =
151+
mkCrossBuildShell "x86_64-apple-darwin";
104152
};
105153

106154
checks = rec {

0 commit comments

Comments
 (0)