Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/debian-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ jobs:
docker-image: ubuntu:${{ inputs.ubuntu-version }}
# Add the Go backports PPA if we're testing a Ubuntu release which
# doesn't have the required Go version in main.
extra-apt-repositories: ${{ (inputs.ubuntu-version == 'noble' || inputs.ubuntu-version == 'questing') && 'ppa:ubuntu-enterprise-desktop/golang' || '' }}
extra-apt-repositories: |
${{ (inputs.ubuntu-version == 'noble' || inputs.ubuntu-version == 'questing') && 'ppa:ubuntu-enterprise-desktop/golang' || '' }}
${{ (inputs.ubuntu-version == 'noble' && 'ppa:maxgmr/lp2100266-2' || '') }}
# Extra build dependencies:
# - systemd-dev: Required to read compile time variables from systemd via pkg-config.
extra-source-build-deps: |
Expand Down
7 changes: 6 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ Build-Depends: debhelper-compat (= 13),
dh-exec,
dh-golang,
dctrl-tools,
cargo (>= 1.82) | cargo-1.82,
# FIXME: We need a newer cargo to be able to update our Rust dependencies.
# These are the newest versions currently available in the active Ubuntu releases:
# * Noble: cargo-1.91
# * Questing: cargo-1.88
# * Resolute: cargo (>= 1.91)
cargo (>= 1.91) | cargo-1.91 | cargo-1.88,
# FIXME: We need cargo-vendor-filterer starting from plucky, but noble isn't ready yet
# so workaround it, making it kind of optional, and requiring it only on versions after
# noble (controlled via base-files version that matches the one in noble).
Expand Down
43 changes: 43 additions & 0 deletions debian/get-depends-cargo-bin-path.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

set -eu

debian_path=$(dirname "$0")
min_cargo_versions=$(grep-dctrl -s Build-Depends -n - "${debian_path}"/control | \
grep -v '^\s*#' | \
grep -oP '(?<=cargo-)[0-9.]+')

if [ -z "${min_cargo_versions}" ]; then
echo >&2 "No cargo version specified in Build-Depends."
exit 1
fi

default_cargo_wrapper="/usr/share/cargo/bin/cargo"
default_cargo_wrapper_dir="${default_cargo_wrapper%/cargo}"
default_cargo_version=$(dpkg-query -W -f='${Version}' cargo 2>/dev/null || true)

for min_cargo_version in ${min_cargo_versions}; do
versioned_cargo_wrapper="/usr/lib/rust-${min_cargo_version}/share/cargo/bin/cargo"
versioned_cargo_wrapper_dir="${versioned_cargo_wrapper%/cargo}"
versioned_bin_dir="/usr/lib/rust-${min_cargo_version}/bin"

if [ -x "${default_cargo_wrapper}" ] && \
dpkg --compare-versions "${default_cargo_version}" ge "${min_cargo_version}" 2>/dev/null; then
echo >&2 "Using default cargo at ${default_cargo_wrapper} (version ${default_cargo_version})"
echo "${default_cargo_wrapper_dir}"
exit 0
else
echo >&2 "Default cargo at ${default_cargo_wrapper} does not meet the minimum version requirement of ${min_cargo_version} (found version '${default_cargo_version}')."
fi

if [ -x "${versioned_cargo_wrapper}" ]; then
echo >&2 "Using versioned cargo at ${versioned_cargo_wrapper}"
echo "${versioned_cargo_wrapper_dir}:${versioned_bin_dir}"
exit 0
fi

echo >&2 "Versioned cargo at ${versioned_cargo_wrapper} does not exist or is not executable."
done

echo >&2 "No suitable cargo version found for minimum required version ${min_cargo_versions}."
exit 1
21 changes: 12 additions & 9 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export DH_GOLANG_INSTALL_ALL := 1
# as long as it matches the go.mod go stenza which is the language requirement.
export GOTOOLCHAIN := local

# Use the debian cargo wrapper
export CARGO_PATH := /usr/share/cargo/bin/cargo

# Needed for Rust vendored sources tracking
export CARGO_VENDOR_DIR := $(CURDIR)/vendor_rust

Expand All @@ -50,10 +47,14 @@ export DH_GOLANG_BUILDPKG := \
$(AUTHD_GO_PACKAGE)/pam \
$(NULL)

# We add the required backported version to the $PATH so that if it exists, then
# we can use it. Otherwise we default to the go installed in original $PATH that
# always matches with the latest available go version in the archive.
export PATH := $(shell printenv PATH):$(shell ./debian/get-depends-go-bin-path.sh)
# Prepend the following paths to PATH:
# * The cargo wrapper. This will either be the path to the wrapper installed by
# dh-cargo, or the path to the wrapper installed by the cargo-$VERSION package.
# * The Go executable from the backported Go package. It's possible that no
# backported Go package is installed, because the golang-go package already
# satisfies the dependency. It's still fine to also add the path in that case,
# it will be ignored if it doesn't exist.
export PATH := $(shell ./debian/get-depends-cargo-bin-path.sh):$(shell ./debian/get-depends-go-bin-path.sh):$(shell printenv PATH)

BUILDDIR := $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)

Expand Down Expand Up @@ -89,7 +90,7 @@ override_dh_auto_configure:
# TODO: Drop this when we won't care about noble anymore.
if ! command -v cargo-vendor-filterer 2>/dev/null; then \
env DEB_CARGO_CRATE="$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM)" \
$(CARGO_PATH) prepare-debian "$(CARGO_VENDOR_DIR)"; \
cargo prepare-debian "$(CARGO_VENDOR_DIR)"; \
else \
echo "cargo version: $$(cargo --version)"; \
echo "cargo-vendor-filterer version: $$(cargo-vendor-filterer --version)"; \
Expand All @@ -105,7 +106,9 @@ override_dh_auto_build:
DH_GOLANG_GO_GENERATE=1 dh_auto_build -- $(AUTHD_GO_PACKAGE)/pam

# Build the NSS library
$(CARGO_PATH) build --release
echo "PATH: $(PATH)"
echo "Building NSS library with $$(which cargo) ($$(cargo --version))"
cargo build --release

# Build the daemon
dh_auto_build -- $(AUTHD_GO_PACKAGE)/cmd/authd
Expand Down
6 changes: 4 additions & 2 deletions debian/vendor-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ if ! command -v cargo-vendor-filterer 2>/dev/null; then
fi

# Print the versions of cargo and cargo-vendor-filterer for debugging purposes.
echo "Using cargo version: $(${CARGO_PATH} --version)"
echo "PATH: $PATH"
echo "Using cargo: $(which cargo)"
echo "Using cargo version: $(cargo --version)"
echo "Using cargo-vendor-filterer version: $(cargo-vendor-filterer --version)"

# Some crates are shipped with .a files, which get removed by the helpers during the package build as a safety measure.
# This results in cargo failing to compile, since the files (which are listed in the checksums) are not there anymore.
# For those crates, we need to replace their checksum with a more general one that only lists the crate checksum, instead of each file.
${CARGO_PATH} vendor-filterer "${CARGO_VENDOR_DIR}"
cargo vendor-filterer "${CARGO_VENDOR_DIR}"
Loading