* [pbs-devel] [PATCH proxmox-backup] fix static build
@ 2025-06-23 6:17 Fabian Grünbichler
2025-06-23 7:50 ` Fabian Grünbichler
0 siblings, 1 reply; 4+ messages in thread
From: Fabian Grünbichler @ 2025-06-23 6:17 UTC (permalink / raw)
To: pbs-devel
`cargo rustc` only passes the flags (like `target-feature` in this case) for
the final invocation, not for any dependency compilation.
unfortunately, switching to `cargo build` is not straight-forward:
- during a package build, $CARGO is the cargo wrapper which only honors
RUSTFLAGS in its `prepare-debian` invocation
- rustflags in cargo's config.toml are global/per target
- the unstable override that would allow setting them per profile is broken
- and it would only work for the final invocation anyway, just like `cargo rustc`
as a stop-gap measure, let's duplicate and adapt the generated config.toml, and
select it explicitly when doing the static compilation as part of the package
build. manual `make proxmox-backup-client-static` can still just pass RUSTFLAGS
via the environment..
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
verified that this passes the right --target-feature to the build, and that
code guarded under that feature with an intentionally introduced compilation
error trips up the static client build..
sed is not my strongest suite, so feel free to make that part in d/rules
nicer..
we could also put some of the variables into a shared file source by Makefile
and d/rules, maybe..
Makefile | 14 +++++++++-----
debian/rules | 13 +++++++++++++
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/Makefile b/Makefile
index 1ae8da6f5..f14b4d8ce 100644
--- a/Makefile
+++ b/Makefile
@@ -38,19 +38,23 @@ SUBCRATES != cargo metadata --no-deps --format-version=1 \
| grep "$$PWD/" \
| sed -e "s!.*$$PWD/!!g" -e 's/\#.*$$//g' -e 's/)$$//g'
+# sync with debian/rules!
STATIC_TARGET_DIR := target/static-build
-
ifeq ($(BUILD_MODE), release)
CARGO_BUILD_ARGS += --release --target $(DEB_HOST_RUST_TYPE)
+CARGO_STATIC_CONFIG ?= --config debian/cargo_home/config.static.toml
+CARGO_STATIC_BUILD_ARGS += $(CARGO_STATIC_CONFIG) --release --target $(DEB_HOST_RUST_TYPE) --target-dir $(STATIC_TARGET_DIR)
COMPILEDIR := target/$(DEB_HOST_RUST_TYPE)/release
STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/release
else
CARGO_BUILD_ARGS += --target $(DEB_HOST_RUST_TYPE)
+CARGO_STATIC_BUILD_ARGS += --target $(DEB_HOST_RUST_TYPE) --target-dir $(STATIC_TARGET_DIR)
COMPILEDIR := target/$(DEB_HOST_RUST_TYPE)/debug
STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/debug
endif
STATIC_RUSTC_FLAGS := -C target-feature=+crt-static -L $(STATIC_COMPILEDIR)/deps-stubs/
+# end sync with debian/rules
ifeq ($(valgrind), yes)
CARGO_BUILD_ARGS += --features valgrind
@@ -209,11 +213,11 @@ $(STATIC_BINS) &:
mkdir -p $(STATIC_COMPILEDIR)/deps-stubs/ && \
echo '!<arch>' > $(STATIC_COMPILEDIR)/deps-stubs/libsystemd.a # workaround for to greedy linkage and proxmox-systemd
OPENSSL_STATIC=1 \
- $(CARGO) rustc $(CARGO_BUILD_ARGS) --package pxar-bin --bin pxar \
- --target-dir $(STATIC_TARGET_DIR) -- $(STATIC_RUSTC_FLAGS)
+ RUSTFLAGS="$(STATIC_RUSTC_FLAGS)" \
+ $(CARGO) build $(CARGO_STATIC_BUILD_ARGS) --package pxar-bin --bin pxar
OPENSSL_STATIC=1 \
- $(CARGO) rustc $(CARGO_BUILD_ARGS) --package proxmox-backup-client --bin proxmox-backup-client \
- --target-dir $(STATIC_TARGET_DIR) -- $(STATIC_RUSTC_FLAGS)
+ RUSTFLAGS="$(STATIC_RUSTC_FLAGS)" \
+ $(CARGO) build $(CARGO_STATIC_BUILD_ARGS) --package proxmox-backup-client --bin proxmox-backup-client
.PHONY: lint
lint:
diff --git a/debian/rules b/debian/rules
index 70cec4754..6f1773eaf 100755
--- a/debian/rules
+++ b/debian/rules
@@ -7,6 +7,16 @@ include /usr/share/dpkg/pkg-info.mk
include /usr/share/rustc/architecture.mk
export BUILD_MODE=release
+export CARGO_STATIC_CONFIG=--config debian/cargo_home/config.static.toml
+
+# sync with Makefile!
+STATIC_TARGET_DIR := target/static-build
+ifeq ($(BUILD_MODE), release)
+STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/release
+else
+STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/debug
+endif
+# end sync with Makefile!
export CARGO=/usr/share/cargo/bin/cargo
@@ -28,6 +38,9 @@ override_dh_auto_configure:
@perl -ne 'if (/^version\s*=\s*"(\d+(?:\.\d+)+)"/) { my $$v_cargo = $$1; my $$v_deb = "$(DEB_VERSION_UPSTREAM)"; \
die "ERROR: d/changelog <-> Cargo.toml version mismatch: $$v_cargo != $$v_deb\n" if $$v_cargo ne $$v_deb; exit(0); }' Cargo.toml
$(CARGO) prepare-debian $(CURDIR)/debian/cargo_registry --link-from-system
+ # add a new config for static building, sync with Makefile!
+ cp debian/cargo_home/config.toml debian/cargo_home/config.static.toml
+ sed -ie 's!^\(rustflags = .*\)\]$$!\1, "-C", "target-feature=+crt-static", "-L", "$(STATIC_COMPILEDIR)/deps-stubs/"\]!' debian/cargo_home/config.static.toml
# `cargo build` and `cargo install` have different config precedence, symlink
# the wrapper config into a place where `build` picks it up as well..
# https://doc.rust-lang.org/cargo/commands/cargo-install.html#configuration-discovery
--
2.39.5
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup] fix static build
2025-06-23 6:17 [pbs-devel] [PATCH proxmox-backup] fix static build Fabian Grünbichler
@ 2025-06-23 7:50 ` Fabian Grünbichler
2025-06-23 11:41 ` Fabian Grünbichler
0 siblings, 1 reply; 4+ messages in thread
From: Fabian Grünbichler @ 2025-06-23 7:50 UTC (permalink / raw)
To: Proxmox Backup Server development discussion
this currently breaks using the static client pointed at hostnames
instead of IPs on some platforms:
https://forum.proxmox.com/threads/proxmox-backup-client-static-floating-point-exception-core-dumped.167731/#post-779723
so we should probably also backport this (and preceding build fixes) to
bookworm and roll out a fixed package.
On June 23, 2025 8:17 am, Fabian Grünbichler wrote:
> `cargo rustc` only passes the flags (like `target-feature` in this case) for
> the final invocation, not for any dependency compilation.
>
> unfortunately, switching to `cargo build` is not straight-forward:
> - during a package build, $CARGO is the cargo wrapper which only honors
> RUSTFLAGS in its `prepare-debian` invocation
> - rustflags in cargo's config.toml are global/per target
> - the unstable override that would allow setting them per profile is broken
> - and it would only work for the final invocation anyway, just like `cargo rustc`
>
> as a stop-gap measure, let's duplicate and adapt the generated config.toml, and
> select it explicitly when doing the static compilation as part of the package
> build. manual `make proxmox-backup-client-static` can still just pass RUSTFLAGS
> via the environment..
>
> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> ---
> verified that this passes the right --target-feature to the build, and that
> code guarded under that feature with an intentionally introduced compilation
> error trips up the static client build..
>
> sed is not my strongest suite, so feel free to make that part in d/rules
> nicer..
>
> we could also put some of the variables into a shared file source by Makefile
> and d/rules, maybe..
>
> Makefile | 14 +++++++++-----
> debian/rules | 13 +++++++++++++
> 2 files changed, 22 insertions(+), 5 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 1ae8da6f5..f14b4d8ce 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -38,19 +38,23 @@ SUBCRATES != cargo metadata --no-deps --format-version=1 \
> | grep "$$PWD/" \
> | sed -e "s!.*$$PWD/!!g" -e 's/\#.*$$//g' -e 's/)$$//g'
>
> +# sync with debian/rules!
> STATIC_TARGET_DIR := target/static-build
> -
> ifeq ($(BUILD_MODE), release)
> CARGO_BUILD_ARGS += --release --target $(DEB_HOST_RUST_TYPE)
> +CARGO_STATIC_CONFIG ?= --config debian/cargo_home/config.static.toml
> +CARGO_STATIC_BUILD_ARGS += $(CARGO_STATIC_CONFIG) --release --target $(DEB_HOST_RUST_TYPE) --target-dir $(STATIC_TARGET_DIR)
> COMPILEDIR := target/$(DEB_HOST_RUST_TYPE)/release
> STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/release
> else
> CARGO_BUILD_ARGS += --target $(DEB_HOST_RUST_TYPE)
> +CARGO_STATIC_BUILD_ARGS += --target $(DEB_HOST_RUST_TYPE) --target-dir $(STATIC_TARGET_DIR)
> COMPILEDIR := target/$(DEB_HOST_RUST_TYPE)/debug
> STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/debug
> endif
>
> STATIC_RUSTC_FLAGS := -C target-feature=+crt-static -L $(STATIC_COMPILEDIR)/deps-stubs/
> +# end sync with debian/rules
>
> ifeq ($(valgrind), yes)
> CARGO_BUILD_ARGS += --features valgrind
> @@ -209,11 +213,11 @@ $(STATIC_BINS) &:
> mkdir -p $(STATIC_COMPILEDIR)/deps-stubs/ && \
> echo '!<arch>' > $(STATIC_COMPILEDIR)/deps-stubs/libsystemd.a # workaround for to greedy linkage and proxmox-systemd
> OPENSSL_STATIC=1 \
> - $(CARGO) rustc $(CARGO_BUILD_ARGS) --package pxar-bin --bin pxar \
> - --target-dir $(STATIC_TARGET_DIR) -- $(STATIC_RUSTC_FLAGS)
> + RUSTFLAGS="$(STATIC_RUSTC_FLAGS)" \
> + $(CARGO) build $(CARGO_STATIC_BUILD_ARGS) --package pxar-bin --bin pxar
> OPENSSL_STATIC=1 \
> - $(CARGO) rustc $(CARGO_BUILD_ARGS) --package proxmox-backup-client --bin proxmox-backup-client \
> - --target-dir $(STATIC_TARGET_DIR) -- $(STATIC_RUSTC_FLAGS)
> + RUSTFLAGS="$(STATIC_RUSTC_FLAGS)" \
> + $(CARGO) build $(CARGO_STATIC_BUILD_ARGS) --package proxmox-backup-client --bin proxmox-backup-client
>
> .PHONY: lint
> lint:
> diff --git a/debian/rules b/debian/rules
> index 70cec4754..6f1773eaf 100755
> --- a/debian/rules
> +++ b/debian/rules
> @@ -7,6 +7,16 @@ include /usr/share/dpkg/pkg-info.mk
> include /usr/share/rustc/architecture.mk
>
> export BUILD_MODE=release
> +export CARGO_STATIC_CONFIG=--config debian/cargo_home/config.static.toml
> +
> +# sync with Makefile!
> +STATIC_TARGET_DIR := target/static-build
> +ifeq ($(BUILD_MODE), release)
> +STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/release
> +else
> +STATIC_COMPILEDIR := $(STATIC_TARGET_DIR)/$(DEB_HOST_RUST_TYPE)/debug
> +endif
> +# end sync with Makefile!
>
> export CARGO=/usr/share/cargo/bin/cargo
>
> @@ -28,6 +38,9 @@ override_dh_auto_configure:
> @perl -ne 'if (/^version\s*=\s*"(\d+(?:\.\d+)+)"/) { my $$v_cargo = $$1; my $$v_deb = "$(DEB_VERSION_UPSTREAM)"; \
> die "ERROR: d/changelog <-> Cargo.toml version mismatch: $$v_cargo != $$v_deb\n" if $$v_cargo ne $$v_deb; exit(0); }' Cargo.toml
> $(CARGO) prepare-debian $(CURDIR)/debian/cargo_registry --link-from-system
> + # add a new config for static building, sync with Makefile!
> + cp debian/cargo_home/config.toml debian/cargo_home/config.static.toml
> + sed -ie 's!^\(rustflags = .*\)\]$$!\1, "-C", "target-feature=+crt-static", "-L", "$(STATIC_COMPILEDIR)/deps-stubs/"\]!' debian/cargo_home/config.static.toml
> # `cargo build` and `cargo install` have different config precedence, symlink
> # the wrapper config into a place where `build` picks it up as well..
> # https://doc.rust-lang.org/cargo/commands/cargo-install.html#configuration-discovery
> --
> 2.39.5
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
>
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [pbs-devel] [PATCH proxmox-backup] fix static build
2025-06-23 7:50 ` Fabian Grünbichler
@ 2025-06-23 11:41 ` Fabian Grünbichler
2025-06-30 13:56 ` [pbs-devel] applied: " Wolfgang Bumiller
0 siblings, 1 reply; 4+ messages in thread
From: Fabian Grünbichler @ 2025-06-23 11:41 UTC (permalink / raw)
To: Proxmox Backup Server development discussion
On June 23, 2025 9:50 am, Fabian Grünbichler wrote:
> this currently breaks using the static client pointed at hostnames
> instead of IPs on some platforms:
>
> https://forum.proxmox.com/threads/proxmox-backup-client-static-floating-point-exception-core-dumped.167731/#post-779723
>
> so we should probably also backport this (and preceding build fixes) to
> bookworm and roll out a fixed package.
test build with
f2a4b463799a44b27f28095d849649dea6de747e
63ece39a17972505c57309168a2939e11595d4c5
cherry-picked onto stable-3 before this patch seems to work as expected
with no changes required.
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] applied: [PATCH proxmox-backup] fix static build
2025-06-23 11:41 ` Fabian Grünbichler
@ 2025-06-30 13:56 ` Wolfgang Bumiller
0 siblings, 0 replies; 4+ messages in thread
From: Wolfgang Bumiller @ 2025-06-30 13:56 UTC (permalink / raw)
To: Fabian Grünbichler; +Cc: Proxmox Backup Server development discussion
applied to master (but fixed up the `-ie` in the sed invocation to `-i
-e`, since `-i` takes an optional argument and the `e` was used to
create a backup file with a literal "e" suffix on the file name.)
also applied to stable-3 with the commits below cherry picked
On Mon, Jun 23, 2025 at 01:41:27PM +0200, Fabian Grünbichler wrote:
> On June 23, 2025 9:50 am, Fabian Grünbichler wrote:
> > this currently breaks using the static client pointed at hostnames
> > instead of IPs on some platforms:
> >
> > https://forum.proxmox.com/threads/proxmox-backup-client-static-floating-point-exception-core-dumped.167731/#post-779723
> >
> > so we should probably also backport this (and preceding build fixes) to
> > bookworm and roll out a fixed package.
>
> test build with
>
> f2a4b463799a44b27f28095d849649dea6de747e
> 63ece39a17972505c57309168a2939e11595d4c5
>
> cherry-picked onto stable-3 before this patch seems to work as expected
> with no changes required.
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-30 13:56 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-23 6:17 [pbs-devel] [PATCH proxmox-backup] fix static build Fabian Grünbichler
2025-06-23 7:50 ` Fabian Grünbichler
2025-06-23 11:41 ` Fabian Grünbichler
2025-06-30 13:56 ` [pbs-devel] applied: " Wolfgang Bumiller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox