Skip to content

Commit 44d37e4

Browse files
committed
build: statically linked packages
StGit is now statically linked and uses musl when built for deb and rpm packages. This should hopefully maximize portability across various deb and rpm distributions. Also build packages for i686 and aarch64. The INSTALL.md file is updated with details about the additional setup needed to cross-compile these targets. Fixes: #324
1 parent 4a3c8e9 commit 44d37e4

File tree

3 files changed

+142
-24
lines changed

3 files changed

+142
-24
lines changed

.github/workflows/ci.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: dtolnay/rust-toolchain@master
2121
with:
2222
toolchain: stable
23+
targets: i686-unknown-linux-musl,x86_64-unknown-linux-musl,aarch64-unknown-linux-musl
2324
components: clippy, rustfmt
2425
- name: Build
2526
run: |
@@ -46,11 +47,15 @@ jobs:
4647
run: |
4748
make -j2 doc
4849
- name: Build Docs Asciidoctor
50+
env:
51+
USE_ASCIIDOCTOR: "1"
4952
run: |
50-
make -j2 USE_ASCIIDOCTOR=1 doc
53+
make -j2 doc
5154
- name: Install HTML Docs
55+
env:
56+
USE_ASCIIDOCTOR: "1"
5257
run: |
53-
make -j2 USE_ASCIIDOCTOR=1 htmldir="$GITHUB_WORKSPACE"/stgit-html install-html
58+
make -j2 htmldir="$GITHUB_WORKSPACE"/stgit-html install-html
5459
- name: Upload HTML Docs
5560
uses: actions/upload-artifact@v3
5661
with:
@@ -64,19 +69,34 @@ jobs:
6469
uses: baptiste0928/cargo-install@v2
6570
with:
6671
crate: cargo-generate-rpm
72+
args: "--git https://github.com/jpgrayson/cargo-generate-rpm --branch profile-option"
73+
- name: Install aarch64 Dependencies
74+
run: |
75+
sudo apt-get install gcc-aarch64-linux-gnu
76+
- name: Static Build x86_64
77+
run: |
78+
make build-static-x86_64
79+
- name: Static Build i686
80+
run: |
81+
make build-static-i686
82+
- name: Build Build aarch64
83+
env:
84+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: "aarch64-linux-gnu-gcc"
85+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_STRIP: "aarch64-linux-gnu-strip"
86+
run: |
87+
make build-static-aarch64
6788
- name: Build Packages
89+
env:
90+
USE_ASCIIDOCTOR: "1"
91+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: "aarch64-linux-gnu-gcc"
92+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_STRIP: "aarch64-linux-gnu-strip"
6893
run: |
69-
make USE_ASCIIDOCTOR=1 deb rpm
70-
- name: Upload deb
71-
uses: actions/upload-artifact@v3
72-
with:
73-
name: stgit-deb
74-
path: target/debian/stgit_*.deb
75-
- name: Upload rpm
94+
make packages
95+
- name: Upload Packages
7696
uses: actions/upload-artifact@v3
7797
with:
78-
name: stgit-rpm
79-
path: target/generate-rpm/stgit-*.rpm
98+
name: stgit-packages
99+
path: target/pkg/*
80100

81101
build-and-test:
82102
name: Build and Test

INSTALL.md

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ A quick installation of the `stg` binary may be performed with `cargo`:
77
$ cargo install --path=.
88
```
99

10-
The above will install the statically linked `stg` executable to
11-
`~/.cargo/bin`, by default. The `--root` option, `CARGO_INSTALL_ROOT`
12-
environment variable, or `install.root` Cargo config value may be used
13-
to change where StGit is installed.
10+
The above will install the `stg` executable to `~/.cargo/bin`, by
11+
default. The `--root` option, `CARGO_INSTALL_ROOT` environment variable,
12+
or `install.root` Cargo config value may be used to change where StGit
13+
is installed.
1414

1515
The `--locked` option may be passed to `cargo install` to used the
1616
specific dependency versions from the `Cargo.lock` file, otherwise the
@@ -69,3 +69,71 @@ By default the documentation is built using `asciidoc`, but
6969
```shellsession
7070
$ make USE_ASCIIDOCTOR=1 install-man
7171
```
72+
73+
Debian and RPM Packages
74+
-----------------------
75+
76+
The top-level Makefile has targets for building Debian and RPM packages.
77+
None of the distributions that use Debian and RPM packaging provide
78+
StGit 2.x (or 1.x) packages. The deb and rpm packages built from the
79+
StGit repository are meant to fill that gap.
80+
81+
These StGit-provided packages do not necessarily conform to all of the
82+
packaging standards of those distributions. That said, an effort is made
83+
to properly install man pages, shell completions, and vim files in addition
84+
to the `stg` executable.
85+
86+
In order to be maximally portable, the `stg` executable in these packages
87+
is statically linked using [musl][musl].
88+
89+
The following Makefile targets are available to build packages:
90+
91+
- `packages`: build deb and rpm packages for all supported architectures
92+
- `debs`: build deb packages for all supported architectures
93+
- `rpms`: build rpm packages for all supported architectures
94+
- `deb-i686`: build `stgit_x.y.z_i386.deb`
95+
- `deb-x86_64`: build `stgit_x.y.z_amd64.deb`
96+
- `deb-aarch64`: build `stgit_x.y.z_arm64.deb`
97+
- `rpm-i686`: build `stgit-x.y.z-w.i686.rpm`
98+
- `rpm-x86_64`: build `stgit-x.y.z-w.x86_64.rpm`
99+
- `rpm-aarch64`: build `stgit-x.y.z-w.aarch64.rpm`
100+
101+
The generated package files are output to `target/pkg/`.
102+
103+
Rust Dependencies
104+
=================
105+
106+
To build these packages, rust needs to be setup for some additional targets:
107+
108+
- aarch64-unknown-linux-musl
109+
- i686-unknown-linux-musl
110+
- x86_64-unknown-linux-musl
111+
112+
If using `rustup`, these targets can be added by with `rustup target add`.
113+
114+
Cargo Dependencies
115+
==================
116+
117+
The `cargo-deb` and `cargo-generate-rpm` crates are used to generate the
118+
deb and rpm packages, respectively. These may be installed using `cargo
119+
install`.
120+
121+
Linker Setup
122+
============
123+
124+
When cross-compiling, e.g. when building aarch64 targets from an x86_64
125+
host, the cross compiler linker needs to be installed and configured.
126+
127+
On Arch Linux, install `aarch64-linux-gnu-gcc`.
128+
129+
In Debian/Ubuntu environments, install the `gcc-aarch64-linux-gnu`
130+
package.
131+
132+
To configure, add the following to your `~/.cargo/config.toml` file:
133+
134+
```toml
135+
[target.aarch64-unknown-linux-musl]
136+
linker = "aarch64-linux-gnu-gcc"
137+
```
138+
139+
[musl]: https://musl.libc.org/

Makefile

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ TEST_PATCHES ?= ..
2121
build:
2222
$(CARGO) build --profile=$(STG_PROFILE)
2323

24-
build-for-pkg:
25-
$(CARGO) build --profile=for-pkg --no-default-features
26-
2724
all: build doc completion contrib
2825

2926
completion: build
@@ -35,7 +32,7 @@ contrib:
3532
doc: build
3633
$(MAKE) -C Documentation all
3734

38-
.PHONY: all build build-for-pkg completion contrib doc
35+
.PHONY: all build completion contrib doc
3936

4037

4138
install: install-bin
@@ -60,13 +57,46 @@ install-contrib:
6057
.PHONY: install install-all install-bin install-completion install-contrib install-man install-html
6158

6259

63-
deb: completion doc build-for-pkg
64-
$(CARGO_OFFLINE) deb
60+
build-static-i686:
61+
$(CARGO) build --profile=for-pkg --target i686-unknown-linux-musl --no-default-features
62+
63+
build-static-x86_64:
64+
$(CARGO) build --profile=for-pkg --target x86_64-unknown-linux-musl --no-default-features
65+
66+
build-static-aarch64:
67+
$(CARGO) build --profile=for-pkg --target aarch64-unknown-linux-musl --no-default-features
68+
69+
target/pkg:
70+
mkdir -p $@
71+
72+
deb-i686: completion doc target/pkg build-static-i686
73+
$(CARGO_OFFLINE) deb --no-build --no-strip --output target/pkg/ --profile=for-pkg --target=i686-unknown-linux-musl
74+
75+
deb-x86_64: completion doc target/pkg build-static-x86_64
76+
$(CARGO_OFFLINE) deb --no-build --no-strip --output target/pkg/ --profile=for-pkg --target=x86_64-unknown-linux-musl
77+
78+
deb-aarch64: completion doc target/pkg build-static-aarch64
79+
$(CARGO_OFFLINE) deb --no-build --no-strip --output target/pkg/ --profile=for-pkg --target=aarch64-unknown-linux-musl
80+
81+
debs: deb-i686 deb-x86_64 deb-aarch64
82+
83+
rpm-i686: completion doc target/pkg build-static-i686
84+
$(CARGO_OFFLINE) generate-rpm --output target/pkg/ --profile=for-pkg --target=i686-unknown-linux-musl
85+
86+
rpm-x86_64: completion doc target/pkg build-static-x86_64
87+
$(CARGO_OFFLINE) generate-rpm --output target/pkg/ --profile=for-pkg --target=x86_64-unknown-linux-musl
88+
89+
rpm-aarch64: completion doc target/pkg build-static-aarch64
90+
$(CARGO_OFFLINE) generate-rpm --output target/pkg/ --profile=for-pkg --target=aarch64-unknown-linux-musl
91+
92+
rpms: rpm-i686 rpm-x86_64 rpm-aarch64
6593

66-
rpm: completion doc build-for-pkg
67-
$(CARGO_OFFLINE) generate-rpm
94+
packages: debs rpms
6895

69-
.PHONY: deb rpm
96+
.PHONY: packages
97+
.PHONY: debs deb-i686 deb-x86_64 deb-aarch64
98+
.PHONY: rpms rpm-i686 rpm-x86_64 rpm-aarch64
99+
.PHONY: build-static-i686 build-static-x86_64 build-static-aarch64
70100

71101

72102
lint: lint-format lint-clippy lint-api-doc lint-t unit-test

0 commit comments

Comments
 (0)