mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
Integrate rust into s390-tools build system
The rust integration into the s390-tools build system consists of the
following steps:
- Add a subdirectory for the rust code.
- Add a Makefile that forwards rust builds to `cargo`.
- Add a `utils` crate for rust code in s390-tools.
- Add rust stuff for dotfiles:
- gitignore
- editorconfig
- codespellrc (while at it, add an ignore file)
With cargo the rust ecosystem has its own build system which also is
responsible to resolve rust dependencies via downloading the dependencies
from (default) crates.io and discover the source files. Therefore, the
Makefile just calls `cargo build` to forward the build to cargo.
If a rust crate does not require external dependencies, users might call
rustc directly.
A simple `make` will build all the rust targets as well (with --release
specified). Also `make install` will work as usual.
A few Makefile configuration variables are introduced for rust/Cargo:
- HAVE_CARGO (default 1) to toggle the build of rust code using cargo
- CARGOFLAGS to add custom cargo flags, e.g. --offline
- CARGO Cargo binary location defaults to
$(where cargo)
A new global make target is defined to get the current s390-tools
version:
$ make version
2.28.0
rust/Makefile also has the `print-rust-targets` target to print all rust
directories/crates that should be shipped/installed.
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Acked-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
a2baeb2fe2
commit
e6add997eb
5
.codespell.ignore
Normal file
5
.codespell.ignore
Normal file
@@ -0,0 +1,5 @@
|
||||
parm
|
||||
parms
|
||||
crate
|
||||
ser
|
||||
deriver
|
||||
@@ -1,5 +1,4 @@
|
||||
[codespell]
|
||||
ignore-words-list = parm,parms
|
||||
skip = ''
|
||||
ignore-words = .codespell.ignore
|
||||
count = ''
|
||||
quiet-level = 3
|
||||
|
||||
@@ -8,6 +8,12 @@ insert_final_newline = true
|
||||
charset = utf-8
|
||||
indent_style = tab
|
||||
tab_width = 8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.rs]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
tab_width = 4
|
||||
|
||||
[*.sh]
|
||||
shell_variant = bash # used by `shfmt`
|
||||
|
||||
12
.rustfmt.toml
Normal file
12
.rustfmt.toml
Normal file
@@ -0,0 +1,12 @@
|
||||
edition = "2021"
|
||||
newline_style = "Unix"
|
||||
|
||||
# Unstable options that help catching some mistakes in formatting and that we may want to enable
|
||||
# when they become stable.
|
||||
#
|
||||
# They are kept here since they are useful to run from time to time.
|
||||
#format_code_in_doc_comments = true
|
||||
#reorder_impl_items = true
|
||||
#comment_width = 100
|
||||
#wrap_comments = true
|
||||
#normalize_comments = true
|
||||
@@ -5,6 +5,8 @@ Release history for s390-tools (MIT version)
|
||||
|
||||
For Linux kernel version: 6.x
|
||||
|
||||
s390-tools now supports tools written in rust!
|
||||
|
||||
Add new tools / libraries:
|
||||
|
||||
Changes of existing tools:
|
||||
|
||||
5
Makefile
5
Makefile
@@ -15,11 +15,12 @@ TOOL_DIRS = zipl zdump fdasd dasdfmt dasdview tunedasd \
|
||||
vmcp man mon_tools dasdinfo vmur cpuplugd ipl_tools \
|
||||
ziomon iucvterm hyptop cmsfs-fuse qethqoat zfcpdump zdsfs cpumf \
|
||||
systemd hmcdrvfs cpacfstats zdev dump2tar zkey netboot etc zpcictl \
|
||||
genprotimg lsstp hsci hsavmcore chreipl-fcp-mpath ap_tools pvattest
|
||||
genprotimg lsstp hsci hsavmcore chreipl-fcp-mpath ap_tools pvattest \
|
||||
rust
|
||||
else
|
||||
BASELIB_DIRS =
|
||||
LIB_DIRS = libpv
|
||||
TOOL_DIRS = genprotimg pvattest
|
||||
TOOL_DIRS = genprotimg pvattest rust
|
||||
endif
|
||||
|
||||
SUB_DIRS = $(BASELIB_DIRS) $(LIB_DIRS) $(TOOL_DIRS)
|
||||
|
||||
@@ -15,6 +15,11 @@ The package also contains the following files:
|
||||
Package contents
|
||||
----------------
|
||||
|
||||
* rust:
|
||||
all s390-tools that are written in rust and require external crates.
|
||||
Disable the compilation of all tools in `rust/` using HAVE_CARGO=0
|
||||
See the `rust/README.md` for Details
|
||||
|
||||
* dasdfmt:
|
||||
Low-level format ECKD DASDs with the classical Linux disk layout or the new
|
||||
z/OS compatible disk layout.
|
||||
@@ -324,6 +329,7 @@ This table lists additional build or install options:
|
||||
| | | zipl |
|
||||
| initramfs-tools | `HAVE_INITRAMFS` | zdev, zipl |
|
||||
| | `ZDEV_ALWAYS_UPDATE_INITRD` | zdev |
|
||||
| rust | `HAVE_CARGO` | rust/* |
|
||||
|
||||
The s390-tools build process uses "pkg-config" and therefore it must be
|
||||
available.
|
||||
|
||||
49
common.mak
49
common.mak
@@ -8,6 +8,8 @@ ASAN ?= 0
|
||||
ENABLE_WERROR ?= 0
|
||||
OPT_FLAGS ?=
|
||||
MAKECMDGOALS ?=
|
||||
CARGO ?= cargo
|
||||
CARGOFLAGS ?=
|
||||
|
||||
ifeq ($(COMMON_INCLUDED),false)
|
||||
COMMON_INCLUDED := true
|
||||
@@ -89,17 +91,17 @@ define cmd_define_and_export
|
||||
endef
|
||||
|
||||
define define_toolchain_variables
|
||||
$(eval $(call cmd_define_and_export, AS$(1)," AS$(1) ",$(2)as))
|
||||
$(eval $(call cmd_define_and_export, CC$(1)," CC$(1) ",$(2)gcc))
|
||||
$(eval $(call cmd_define_and_export, LINK$(1)," LINK$(1) ",$$(CC$(1))))
|
||||
$(eval $(call cmd_define_and_export, CXX$(1)," CXX$(1) ",$(2)g++))
|
||||
$(eval $(call cmd_define_and_export, LINKXX$(1)," LINKXX$(1) ",$$(CXX$(1))))
|
||||
$(eval $(call cmd_define_and_export, CPP$(1)," CPP$(1) ",$(2)gcc -E))
|
||||
$(eval $(call cmd_define_and_export, AR$(1)," AR$(1) ",$(2)ar))
|
||||
$(eval $(call cmd_define_and_export, NM$(1)," NM$(1) ",$(2)nm))
|
||||
$(eval $(call cmd_define_and_export, STRIP$(1)," STRIP$(1) ",$(2)strip))
|
||||
$(eval $(call cmd_define_and_export,OBJCOPY$(1)," OBJCOPY$(1) ",$(2)objcopy))
|
||||
$(eval $(call cmd_define_and_export,OBJDUMP$(1)," OBJDUMP$(1) ",$(2)objdump))
|
||||
$(eval $(call cmd_define_and_export, AS$(1)," AS$(1) ",$(2)as))
|
||||
$(eval $(call cmd_define_and_export, CC$(1)," CC$(1) ",$(2)gcc))
|
||||
$(eval $(call cmd_define_and_export, LINK$(1)," LINK$(1) ",$$(CC$(1))))
|
||||
$(eval $(call cmd_define_and_export, CXX$(1)," CXX$(1) ",$(2)g++))
|
||||
$(eval $(call cmd_define_and_export, LINKXX$(1)," LINKXX$(1) ",$$(CXX$(1))))
|
||||
$(eval $(call cmd_define_and_export, CPP$(1)," CPP$(1) ",$(2)gcc -E))
|
||||
$(eval $(call cmd_define_and_export, AR$(1)," AR$(1) ",$(2)ar))
|
||||
$(eval $(call cmd_define_and_export, NM$(1)," NM$(1) ",$(2)nm))
|
||||
$(eval $(call cmd_define_and_export, STRIP$(1)," STRIP$(1) ",$(2)strip))
|
||||
$(eval $(call cmd_define_and_export,OBJCOPY$(1)," OBJCOPY$(1) ",$(2)objcopy))
|
||||
$(eval $(call cmd_define_and_export,OBJDUMP$(1)," OBJDUMP$(1) ",$(2)objdump))
|
||||
$(eval PKG_CONFIG$(1) = pkg-config)
|
||||
$(eval export PKG_CONFIG$(1))
|
||||
endef
|
||||
@@ -118,12 +120,16 @@ endif
|
||||
$(call define_toolchain_variables,_FOR_BUILD,)
|
||||
$(call define_toolchain_variables,,$(CROSS_COMPILE))
|
||||
|
||||
$(eval $(call cmd_define,RUNTEST," RUNTEST ",$(S390_TEST_LIB_PATH)/s390_runtest))
|
||||
$(eval $(call cmd_define, CAT," CAT ",cat))
|
||||
$(eval $(call cmd_define, SED," SED ",sed))
|
||||
$(eval $(call cmd_define, GZIP," GZIP ",gzip))
|
||||
$(eval $(call cmd_define, MV," MV ",mv))
|
||||
$(eval $(call cmd_define, PERLC," PERLC ",perl -c))
|
||||
|
||||
$(eval $(call cmd_define, RUNTEST," RUNTEST ",$(S390_TEST_LIB_PATH)/s390_runtest))
|
||||
$(eval $(call cmd_define, CAT," CAT ",cat))
|
||||
$(eval $(call cmd_define, SED," SED ",sed))
|
||||
$(eval $(call cmd_define, GZIP," GZIP ",gzip))
|
||||
$(eval $(call cmd_define, MV," MV ",mv))
|
||||
$(eval $(call cmd_define, PERLC," PERLC ",perl -c))
|
||||
$(eval $(call cmd_define,CARGO_BUILD," CARGO BUILD ",$(CARGO) build))
|
||||
$(eval $(call cmd_define,CARGO_TEST, " CARGO TEST ",$(CARGO) test))
|
||||
$(eval $(call cmd_define,CARGO_CLEAN," CARGO CLEAN ",$(CARGO) clean))
|
||||
|
||||
CHECK = sparse
|
||||
CHECK_SILENT := $(CHECK)
|
||||
@@ -133,8 +139,10 @@ SKIP = echo " SKIP $(call reldir) due to"
|
||||
|
||||
INSTALL = install
|
||||
CP = cp
|
||||
ALL_CARGOFLAGS := $(CARGOFLAGS)
|
||||
ifneq ("${V}","1")
|
||||
MAKEFLAGS += --quiet
|
||||
ALL_CARGOFLAGS += --quiet
|
||||
echocmd=echo $1$(call reldir)$2;
|
||||
RUNTEST += > /dev/null 2>&1
|
||||
else
|
||||
@@ -397,6 +405,11 @@ else
|
||||
$(error Please install either 'compiledb' or 'bear')
|
||||
endif
|
||||
|
||||
# Prints the s390-tools release string
|
||||
version:
|
||||
$(info $(S390_TOOLS_RELEASE))
|
||||
.PHONY: version
|
||||
|
||||
# Automatic dependency generation
|
||||
#
|
||||
# Create ".o.d" dependency files with the -MM compile option for all ".c" and
|
||||
@@ -507,7 +520,7 @@ install_echo:
|
||||
install: install_echo install_dirs
|
||||
|
||||
clean_echo:
|
||||
$(call echocmd," CLEAN ")
|
||||
$(call echocmd," CLEAN ")
|
||||
clean_gcov:
|
||||
rm -f -- *.gcda *.gcno *.gcov
|
||||
clean_dep:
|
||||
|
||||
14
rust/.gitignore
vendored
Normal file
14
rust/.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
# Generated by Cargo
|
||||
# will have compiled files and executables
|
||||
debug/
|
||||
target/
|
||||
|
||||
# These are backup files generated by rustfmt
|
||||
*.rs.bk
|
||||
|
||||
# Generated during make build can be removed at any point
|
||||
.check-dep-pvtools
|
||||
.check-cargo
|
||||
|
||||
# Ignore lock files by default
|
||||
Cargo.lock
|
||||
81
rust/Makefile
Normal file
81
rust/Makefile
Normal file
@@ -0,0 +1,81 @@
|
||||
include ../common.mak
|
||||
SHELL := /bin/bash
|
||||
HAVE_CARGO ?= 1
|
||||
|
||||
INSTALL_TARGETS := skip-build
|
||||
BUILD_TARGETS := skip-build
|
||||
CARGO_TARGETS :=
|
||||
CARGO_TEST_TARGETS :=
|
||||
|
||||
ifneq (${HAVE_CARGO},0)
|
||||
CARGO_TARGETS :=
|
||||
|
||||
BUILD_TARGETS = $(CARGO_TARGETS)
|
||||
INSTALL_TARGETS := install-rust-tools install-man
|
||||
CARGO_TEST_TARGETS = $(addsuffix, _test, $(CARGO_TARGETS))
|
||||
|
||||
endif
|
||||
|
||||
# build release targets by default
|
||||
ifeq ("${D}","0")
|
||||
ALL_CARGOFLAGS += --release
|
||||
endif
|
||||
|
||||
# the cc crate uses these variables to compile c code. It does not open a shell
|
||||
# to call the compiler, so no echo etc. allowed here, just a path to a program
|
||||
$(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)
|
||||
|
||||
|
||||
$(CARGO_TEST_TARGETS): .check-cargo .no-cross-compile
|
||||
$(CARGO_TEST) --manifest-path=$@/Cargo.toml --all-features $(CARGOFLAGS)
|
||||
.PHONY: $(CARGO_TEST_TARGETS)
|
||||
|
||||
skip-build:
|
||||
echo " SKIP rust-tools due to unresolved dependencies"
|
||||
|
||||
all: $(BUILD_TARGETS)
|
||||
install: $(INSTALL_TARGETS)
|
||||
|
||||
print-rust-targets:
|
||||
echo $(BUILD_TARGETS)
|
||||
|
||||
clean:
|
||||
$(foreach target,$(CARGO_TARGETS),\
|
||||
$(CARGO_CLEAN) --manifest-path=$(target)/Cargo.toml ${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} ;)
|
||||
|
||||
install-rust-tools: $(BUILD_TARGETS)
|
||||
$(INSTALL) -d -m 755 $(DESTDIR)$(USRBINDIR)
|
||||
$(foreach target,$(CARGO_TARGETS),\
|
||||
$(INSTALL) $(target)/target/release/$(target) $(DESTDIR)$(USRBINDIR);)
|
||||
|
||||
install-man:
|
||||
$(foreach target,$(CARGO_TARGETS),\
|
||||
$(INSTALL) -m 644 $(target)/man/*.1 -t $(DESTDIR)$(MANDIR)/man1;)
|
||||
|
||||
.PHONY: all install clean skip-build install-rust-tools print-rust-targets install-man rust-test
|
||||
|
||||
.check-cargo:
|
||||
ifeq ($(shell command -v $(CARGO)),)
|
||||
$(call check_dep, \
|
||||
"rust/cargo", \
|
||||
"invalid-incl", \
|
||||
"cargo", \
|
||||
"HAVE_CARGO=0")
|
||||
endif
|
||||
touch $@
|
||||
|
||||
.no-cross-compile:
|
||||
ifneq ($(HOST_ARCH), $(BUILD_ARCH))
|
||||
$(error Cross compiling is not supported for rust code. Specify HAVE_CARGO=0 to disable rust compilation)
|
||||
endif
|
||||
.PHONY: .no-cross-compile
|
||||
5
rust/utils/Cargo.toml
Normal file
5
rust/utils/Cargo.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
[package]
|
||||
name = "utils"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
29
rust/utils/src/lib.rs
Normal file
29
rust/utils/src/lib.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
//! Utils for s390-tools written in rust.
|
||||
//! Not intened to be used outside of s390-tools.
|
||||
//!
|
||||
//! Copyright IBM Corp. 2023
|
||||
|
||||
/// Get the s390-tools release string
|
||||
///
|
||||
/// Provides the s390-tools release string.
|
||||
/// For release builds this reqquires the environment variable
|
||||
/// `S390_TOOLS_RELEASE` to be present at compile time.
|
||||
/// For debug builds this value defaults to `DEBUG_BUILD`
|
||||
/// if that variable is not present.
|
||||
/// Should only be used by binary targets!!
|
||||
///
|
||||
/// Collapses to a compile time constant, that is likely to be inlined
|
||||
/// by the compiler in release builds.
|
||||
#[macro_export]
|
||||
macro_rules! release_string {
|
||||
() => {{
|
||||
#[cfg(debug_assertions)]
|
||||
match option_env!("S390_TOOLS_RELEASE") {
|
||||
Some(ver) => ver,
|
||||
None => "DEBUG BUILD",
|
||||
}
|
||||
#[cfg(not(debug_assertions))]
|
||||
env!("S390_TOOLS_RELEASE", "env 'S390_TOOLS_RELEASE' must be set for release builds. Trigger build using the s390-tools build system or export the variable yourself")
|
||||
}};
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
include ../common.mak
|
||||
|
||||
CPIOINIT = $(call echocmd," CPIOINI ",/$@)./cpioinit
|
||||
CPIOINIT = $(call echocmd," CPIOINI ",/$@)./cpioinit
|
||||
INSTALL_SCRIPTS = 10-zfcpdump.install
|
||||
|
||||
ALL_CFLAGS += -fno-sanitize=all
|
||||
|
||||
Reference in New Issue
Block a user