From 32b68a5fad652589c85eae098e799563b88864b5 Mon Sep 17 00:00:00 2001 From: Steffen Eiden Date: Wed, 4 Oct 2023 10:59:34 +0200 Subject: [PATCH] rust: Create workspace A workspaces simplifies the build and packaging process significantly. All build artifacts and binaries are now built in a single location (e.g., rust/target/release/*), and a unified dependency resolution is used. Hence one Cargo.lock for all crates at rust/Cargo.lock. Closes: https://github.com/ibm-s390-linux/s390-tools/issues/156 Reviewed-by: Marc Hartmayer Signed-off-by: Steffen Eiden --- rust/Cargo.toml | 15 ++++++++++ rust/Makefile | 43 +++++++++++---------------- rust/README.md | 20 +++++++++++-- rust/pv/Cargo.toml | 8 ++--- rust/pv/openssl_extensions/Cargo.toml | 4 +-- rust/pvsecret/Cargo.toml | 8 ++--- rust/utils/Cargo.toml | 4 +-- 7 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 rust/Cargo.toml diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 00000000..65a70a97 --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,15 @@ +[workspace] +members = [ + "pv", + "pvsecret", + "utils", +] +resolver = "2" + +[workspace.package] +edition = "2021" +license = "MIT" + +[profile.release] +lto = true +panic = "abort" diff --git a/rust/Makefile b/rust/Makefile index 420bafd0..e4e98859 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -15,16 +15,17 @@ ifneq (${HAVE_CARGO},0) BUILD_TARGETS = $(CARGO_TARGETS) INSTALL_TARGETS := install-rust-tools install-man - CARGO_TEST_TARGETS = $(addsuffix, _test, $(CARGO_TARGETS)) + CARGO_TEST_TARGETS = $(addsuffix .test, $(CARGO_TARGETS)) ifneq (${HAVE_OPENSSL},0) ifneq (${HAVE_LIBCURL},0) PV_TARGETS := pvsecret - PV_BUILD_TARGETS = $(PV_TARGETS) - CARGO_TEST_TARGETS += $(addsuffix, _test, $(PV_TARGETS)) pv + PV_BUILD_TARGETS := $(PV_TARGETS) + CARGO_TEST_TARGETS += $(addsuffix .test,pv $(PV_TARGETS)) endif #LIBCURL endif #OPENSSL + TEST_TARGETS := $(addsuffix _build,$(CARGO_TEST_TARGETS)) endif #CARGO BUILD_TARGETS += $(PV_BUILD_TARGETS) @@ -39,18 +40,15 @@ endif $(BUILD_TARGETS) rust-test: CC = $(CC_SILENT) $(BUILD_TARGETS) rust-test: AR = $(AR_SILENT) -$(CARGO_TARGETS): .check-cargo .no-cross-compile - $(CARGO_BUILD) --manifest-path=$@/Cargo.toml $(ALL_CARGOFLAGS) -.PHONY: $(CARGO_TARGETS) +$(PV_TARGETS): .check-dep-pvtools +$(PV_TARGETS) $(CARGO_TARGETS): .check-cargo .no-cross-compile + $(CARGO_BUILD) --bin $@ $(ALL_CARGOFLAGS) +.PHONY: $(PV_TARGETS) $(CARGO_TARGETS) - -$(CARGO_TEST_TARGETS): .check-cargo .no-cross-compile - $(CARGO_TEST) --manifest-path=$@/Cargo.toml --all-features $(CARGOFLAGS) -.PHONY: $(CARGO_TEST_TARGETS) - -$(PV_TARGETS): .check-cargo .no-cross-compile .check-dep-pvtools - $(CARGO_BUILD) --manifest-path=$@/Cargo.toml $(ALL_CARGOFLAGS) -.PHONY: $(PV_TARGETS) +$(TEST_TARGETS): ALL_CARGOFLAGS += --no-run +$(CARGO_TEST_TARGETS) $(TEST_TARGETS): .check-cargo .no-cross-compile + $(CARGO_TEST) --package $(basename $@) --all-features $(ALL_CARGOFLAGS) +.PHONY: $(TEST_TARGETS) $(CARGO_TEST_TARGETS) skip-build: echo " SKIP rust-tools due to unresolved dependencies" @@ -65,22 +63,17 @@ print-rust-targets: echo $(BUILD_TARGETS) clean: - $(foreach target,$(CARGO_TARGETS),\ - $(CARGO_CLEAN) --manifest-path=$(target)/Cargo.toml ${ALL_CARGOFLAGS} ;) - $(foreach target,$(PV_TARGETS),\ - $(CARGO_CLEAN) --manifest-path=$(target)/Cargo.toml ${ALL_CARGOFLAGS} ;) + $(CARGO_CLEAN) ${ALL_CARGOFLAGS} $(RM) -- .check-dep-pvtools .detect-openssl.dep.c .check-cargo -rust-test: .check-cargo .no-cross-compile - $(foreach target,$(CARGO_TEST_TARGETS),\ - $(CARGO_TEST) --manifest-path=$(target)/Cargo.toml --all-features ${ALL_CARGOFLAGS} ;) +rust-test: $(CARGO_TEST_TARGETS) install-rust-tools: $(BUILD_TARGETS) $(INSTALL) -d -m 755 $(DESTDIR)$(USRBINDIR) $(foreach target,$(CARGO_TARGETS),\ - $(INSTALL) $(target)/target/release/$(target) $(DESTDIR)$(USRBINDIR);) + $(INSTALL) target/release/$(target) $(DESTDIR)$(USRBINDIR);) $(foreach target,$(PV_TARGETS),\ - $(INSTALL) $(target)/target/release/$(target) $(DESTDIR)$(USRBINDIR);) + $(INSTALL) target/release/$(target) $(DESTDIR)$(USRBINDIR);) install-man: $(foreach target,$(CARGO_TARGETS),\ @@ -118,13 +111,13 @@ endif .check-dep-pvtools: .detect-openssl.dep.c $(call check_dep, \ - "$(BIN_PROGRAM)", \ + "Rust-pv", \ $^, \ "openssl-devel / libssl-dev version >= 1.1.1", \ "HAVE_OPENSSL=0", \ "-I.") $(call check_dep, \ - "$(BIN_PROGRAM)", \ + "Rust-pv", \ "curl/curl.h", \ "libcurl-devel", \ "HAVE_LIBCURL=0") diff --git a/rust/README.md b/rust/README.md index 61b0af80..16603bf5 100644 --- a/rust/README.md +++ b/rust/README.md @@ -81,11 +81,27 @@ is a start, but can change over time. Dependencies used by the crates listed above can be used, too. ### Add new tool -To add a new tool issue `cargo new ` in the `rust` directory. +To add a new tool issue `cargo new $TOOLNAME` in the `rust` directory. Add the tool to the _s390-tools_ build system: ```Makefile -CARGO_TARGETS := TOOLNAME +CARGO_TARGETS := $TOOLNAME +``` +Add the library to the _s390-tools_ test list: +```Makefile +CARGO_TEST_TARGETS := $LIBNAME +``` + +Add the tool/library to the cargo workspace: +```toml +[workspace] +members = [ + "pv", + "pvsecret", + "$TOOLNAME", + "$LIBNAME" + "utils", +] ``` ### Versions diff --git a/rust/pv/Cargo.toml b/rust/pv/Cargo.toml index 689d6242..825386a4 100644 --- a/rust/pv/Cargo.toml +++ b/rust/pv/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "pv" version = "0.9.0" -edition = "2021" -license = "MIT" +edition.workspace = true +license.workspace = true [dependencies] libc = "0.2" @@ -30,7 +30,3 @@ lazy_static = "1" default = [] request = ["dep:openssl", "dep:curl", "dep:openssl_extensions", "dep:serde", "dep:clap"] uvsecret = ["dep:byteorder", "dep:serde"] - -[profile.release] -lto = true -panic = "abort" # release builds now do not clean up stack after panics. .1 Mb diff --git a/rust/pv/openssl_extensions/Cargo.toml b/rust/pv/openssl_extensions/Cargo.toml index 17d4c0e5..90907cee 100644 --- a/rust/pv/openssl_extensions/Cargo.toml +++ b/rust/pv/openssl_extensions/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "openssl_extensions" version = "0.1.0" -edition = "2021" -license = "MIT" +edition.workspace = true +license.workspace = true [dependencies] foreign-types = "0.3" diff --git a/rust/pvsecret/Cargo.toml b/rust/pvsecret/Cargo.toml index da4deab3..d1e75b13 100644 --- a/rust/pvsecret/Cargo.toml +++ b/rust/pvsecret/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "pvsecret" version = "0.9.0" -edition = "2021" -license = "MIT" +edition.workspace = true +license.workspace = true [dependencies] anyhow = { version = "1", features = ["std"] } @@ -12,7 +12,3 @@ serde_yaml = "0.9" pv = { path = "../pv", features = ["uvsecret", "request"] } utils = { path = "../utils" } - -[profile.release] -lto = true -panic = "abort" # release builds now do not clean up stack after panics. .1 Mb diff --git a/rust/utils/Cargo.toml b/rust/utils/Cargo.toml index 30bbbc83..215381be 100644 --- a/rust/utils/Cargo.toml +++ b/rust/utils/Cargo.toml @@ -1,5 +1,5 @@ [package] name = "utils" version = "0.1.0" -edition = "2021" -license = "MIT" +edition.workspace = true +license.workspace = true