diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/Makefile.build | 18 | ||||
-rw-r--r-- | scripts/Makefile.lib | 37 | ||||
-rw-r--r-- | scripts/kallsyms.c | 2 | ||||
-rwxr-xr-x | scripts/rust-version.sh | 31 |
4 files changed, 86 insertions, 2 deletions
diff --git a/scripts/Makefile.build b/scripts/Makefile.build index a467b9323442..9b50f2e02026 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -23,10 +23,14 @@ subdir-y := subdir-m := EXTRA_AFLAGS := EXTRA_CFLAGS := +EXTRA_RUSTCFLAGS := +EXTRA_CARGOFLAGS := EXTRA_CPPFLAGS := EXTRA_LDFLAGS := asflags-y := ccflags-y := +rustcflags-y := +cargoflags-y := cppflags-y := ldflags-y := @@ -299,6 +303,20 @@ quiet_cmd_cc_lst_c = MKLST $@ $(obj)/%.lst: $(src)/%.c FORCE $(call if_changed_dep,cc_lst_c) +# Compile Rust sources (.rs) via cargo +# --------------------------------------------------------------------------- + +quiet_cmd_cargo = CARGO $(quiet_modtag) $@ + cmd_cargo = cd $(src) && $(CARGO) build $(cargo_flags) + +# The .o from the Rust staticlib +$(obj)/%.o: $(src)/out/lib%.a + $(Q)$(LD) -r -o $@ --whole-archive $< + +# The Rust staticlib from cargo +$(obj)/out/lib%.a: FORCE + $(call cmd,cargo) + # Compile assembler sources (.S) # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3d599716940c..939062f389d3 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -20,6 +20,8 @@ endif # flags that take effect in current and sub directories KBUILD_AFLAGS += $(subdir-asflags-y) KBUILD_CFLAGS += $(subdir-ccflags-y) +KBUILD_RUSTCFLAGS += $(subdir-rustcflags-y) +KBUILD_CARGOFLAGS += $(subdir-cargoflags-y) # Figure out what we need to build from the various variables # =========================================================================== @@ -126,6 +128,14 @@ _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \ $(filter-out $(ccflags-remove-y), \ $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \ $(CFLAGS_$(target-stem).o)) +_rustc_flags = $(filter-out $(RUSTCFLAGS_REMOVE_$(target-stem).o), \ + $(filter-out $(rustcflags-remove-y), \ + $(KBUILD_RUSTCFLAGS) $(rustcflags-y)) \ + $(RUSTCFLAGS_$(target-stem).o)) +_cargo_flags = $(filter-out $(CARGOFLAGS_REMOVE_$(target-stem).o), \ + $(filter-out $(cargoflags-remove-y), \ + $(KBUILD_CARGOFLAGS) $(cargoflags-y)) \ + $(CARGOFLAGS_$(target-stem).o)) _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \ $(filter-out $(asflags-remove-y), \ $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \ @@ -185,7 +195,8 @@ _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) endif endif -part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) +# TODO: quick hack +part-of-module = $(if $(filter $(basename $@).o,$(real-obj-m)),y,$(and $(real-obj-m),$(shell echo $@ | sed -E 's!.+/out/lib.+\.a!y!;t;d'))) quiet_modtag = $(if $(part-of-module),[M], ) modkern_cflags = \ @@ -193,6 +204,16 @@ modkern_cflags = \ $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) +modkern_rustcflags = \ + $(if $(part-of-module), \ + $(KBUILD_RUSTCFLAGS_MODULE) $(RUSTCFLAGS_MODULE), \ + $(KBUILD_RUSTCFLAGS_KERNEL) $(RUSTCFLAGS_KERNEL)) + +modkern_cargoflags = \ + $(if $(part-of-module), \ + $(KBUILD_CARGOFLAGS_MODULE) $(CARGOFLAGS_MODULE), \ + $(KBUILD_CARGOFLAGS_KERNEL) $(CARGOFLAGS_KERNEL)) + modkern_aflags = $(if $(part-of-module), \ $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) @@ -202,6 +223,20 @@ c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_c_flags) $(modkern_cflags) \ $(basename_flags) $(modname_flags) +# Needed for the Rust bindings +# TODO: we unconditionally pass `KBUILD_CFLAGS_MODULE` to avoid having +# dual bindings, but ideally we should generate two set of bindings +RUST_BINDGEN_CFLAGS = $(c_flags) $(KBUILD_CFLAGS_MODULE) +export RUST_BINDGEN_CFLAGS + +rustc_flags = $(_rustc_flags) $(modkern_rustcflags) + +# Passed by cargo +RUSTFLAGS = $(rustc_flags) +export RUSTFLAGS + +cargo_flags = $(_cargo_flags) $(modkern_cargoflags) + a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ $(_a_flags) $(modkern_aflags) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 0096cd965332..a880a2c20b3d 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -27,7 +27,7 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) -#define KSYM_NAME_LEN 128 +#define KSYM_NAME_LEN 256 struct sym_entry { unsigned long long addr; diff --git a/scripts/rust-version.sh b/scripts/rust-version.sh new file mode 100755 index 000000000000..67b6d31688e2 --- /dev/null +++ b/scripts/rust-version.sh @@ -0,0 +1,31 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# rust-version rust-command +# +# Print the compiler version of `rust-command' in a 5 or 6-digit form +# such as `14502' for rustc-1.45.2 etc. +# +# Returns 0 if not found (so that Kconfig does not complain) +compiler="$*" + +if [ ${#compiler} -eq 0 ]; then + echo "Error: No compiler specified." >&2 + printf "Usage:\n\t$0 <rust-command>\n" >&2 + exit 1 +fi + +if ! command -v $compiler >/dev/null 2>&1; then + echo 0 + exit 0 +fi + +VERSION=$($compiler --version | cut -f2 -d' ') + +# Cut suffix if any (e.g. `-dev`) +VERSION=$(echo $VERSION | cut -f1 -d'-') + +MAJOR=$(echo $VERSION | cut -f1 -d'.') +MINOR=$(echo $VERSION | cut -f2 -d'.') +PATCHLEVEL=$(echo $VERSION | cut -f3 -d'.') +printf "%d%02d%02d\\n" $MAJOR $MINOR $PATCHLEVEL |