Skip to content

Commit

Permalink
rpm packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
roylaurie committed May 7, 2024
1 parent bc795f0 commit 440e595
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 10 deletions.
43 changes: 35 additions & 8 deletions Building.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ Most of these steps are for cross-compilation.

## Requirements

*Tested against Ubuntu Desktop 23*

Debian packaging requires:
```bash
sudo apt install \
pkg-config build-essential \
cross-build-essential-arm64 \
cross-build-essential-armhf
```

Snap packaging requires:
```bash
sudo snap install snapcraft --classic
```

Cross-compiling requires:
```bash
cargo install cross
Expand All @@ -15,27 +30,39 @@ Debian packaging requires:
cargo install carg-deb
```

Debian packaging requires:
RPM packaging requires:
```bash
sudo apt install \
pkg-config build-essential \
cross-build-essential-arm64 \
cross-build-essential-armhf
cargo install cargo-generate-rpm
```

## Compiling
## Cross-Compiling

```bash
# for each rustup TARGET ...
cross --release --target=$TARGET
```

# Packaging for Debian
## Packaging for Debian

Requires the `cross-build-essential-` packages

```bash
# for each Debian rustup TARGET, after compiling ...
# for each linux rust TARGET, after compiling ...
cargo deb --target=$TARGET --no-build
```


## Packaging for Snap

From the project root:
```bash
snapcraft
```


## Packaging for RPM

```bash
# for each linux rust TARGET, after compiling ...
cargo generate-rpm --target=$TARGET
```
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ categories = ["command-line-utilities", "filesystem"]
name = "bak"
path = "src/main.rs"

[profile.release]
strip = "symbols"

[package.metadata.generate-rpm]
assets = [
{ source = "target/release/bak", dest = "/usr/bin/bak", mode = "755" }
]

[dependencies]
clap = { version = "4", features = ["derive"] }
colored = "2"
Expand All @@ -23,3 +31,4 @@ thiserror = "1"
[dev-dependencies]
function_name = "0"
file_diff = "1"

1 change: 1 addition & 0 deletions tools/common.lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ RELEASE_TARGETS=(

CARGO_NAME="$(grep -m1 '^name' "${PROJECT_DIR}/Cargo.toml" | cut -d '"' -f 2)"
CARGO_VERSION="$(grep '^version' "${PROJECT_DIR}/Cargo.toml" | cut -d '"' -f 2)"
CARGO_VERSION_EXT="${CARGO_VERSION}-1"
CARGO_BIN_NAME="$(sed -n '/\[\[bin\]\]/,$p' "${PROJECT_DIR}/Cargo.toml" | grep '^name' | cut -d '"' -f 2)"
1 change: 1 addition & 0 deletions tools/package-all.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ echo "began packaging everything"

"${PROJECT_DIR}/tools/package-tarball.bash"
"${PROJECT_DIR}/tools/package-debian.bash"
"${PROJECT_DIR}/tools/package-rpm.bash"
"${PROJECT_DIR}/tools/package-snap.bash"

echo "finished packaging everything"
Expand Down
5 changes: 5 additions & 0 deletions tools/package-debian.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Package Debian .deb files for all releases
# Expects tools/build-release.bash to have been run
set -euo pipefail
shopt -s extglob
PROJECT_DIR="$(realpath "$(dirname "$0")/..")"
source "${PROJECT_DIR}/tools/common.lib.bash"

Expand All @@ -18,5 +19,9 @@ for target in "${RELEASE_TARGETS[@]}"; do
echo "packaging .deb: ${target}"
cargo deb --target "${target}" --no-build --output="${DEB_DIR}"
done

for deb in "${DEB_DIR}"/*.deb; do
sha256sum -b "${deb}" > "${deb}.sha256"
done

echo "finished packaging for Debian"
31 changes: 31 additions & 0 deletions tools/package-rpm.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Package RPMs for all releases
# Expects tools/build-release.bash to have been run
set -euo pipefail
shopt -s extglob
PROJECT_DIR="$(realpath "$(dirname "$0")/..")"
source "${PROJECT_DIR}/tools/common.lib.bash"

echo "began packaging for Red Hat"

RPM_DIR="${PROJECT_DIR}/target/pkg/rpm"
rm -rf "${RPM_DIR}"
mkdir -p "${RPM_DIR}"

cd "${PROJECT_DIR}"

for target in "${RELEASE_TARGETS[@]}"; do
echo "packaging rpm: ${target}"

[[ "$target" != *"linux"* ]] &&
continue

cargo generate-rpm --target "${target}" --output "${RPM_DIR}"
done

for rpm in "${RPM_DIR}"/*.rpm; do
sha256sum -b "${rpm}" > "${rpm}.sha256"
done

echo "finished packaging for Red Hat"

6 changes: 5 additions & 1 deletion tools/package-snap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ rm -rf "${SNAP_DIR}"
mkdir -p "${SNAP_DIR}"

cd "${PROJECT_DIR}"
rm -f "${PROJECT_DIR}"/*.snap"
rm -f "${PROJECT_DIR}"/*.snap

snapcraft

Expand All @@ -23,4 +23,8 @@ mv "${SNAP_DIR}"/bak9_*_amd64.snap "${SNAP_DIR}/bak9_${CARGO_VERSION}_amd64.snap
mv "${SNAP_DIR}"/bak9_*_arm64.snap "${SNAP_DIR}/bak9_${CARGO_VERSION}_arm64.snap"
mv "${SNAP_DIR}"/bak9_*_armhf.snap "${SNAP_DIR}/bak9_${CARGO_VERSION}_armhf.snap"

for snap in "${SNAP_DIR}"/*.snap; do
sha256sum -b "${snap}" > "${snap}.sha256"
done

echo "finished packaging snaps"
7 changes: 6 additions & 1 deletion tools/package-tarball.bash
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ for target in "${RELEASE_TARGETS[@]}"; do

cd "${package_dir}/.."
tar cf "${package_dir_name}.tar.xz" --use-compress-program='xz -T0' "${package_dir_name}"
rm -rf "${package_dir}"
done

rm -rf "${TARBALL_TEMPLATE_DIR}"

sha256sum -b "${package_dir_name}.tar.xz" > "${package_dir_name}.tar.xz.sha256"
for tarball in "${TARBALL_DIR}"/*.tar.xz; do
sha256sum -b "${tarball}" > "${tarball}.sha256"
done

echo "finished packaging tarballs"
Expand Down

0 comments on commit 440e595

Please sign in to comment.