Skip to content

Commit

Permalink
Merge pull request torvalds#694 from ojeda/target
Browse files Browse the repository at this point in the history
rust: generate target specification files on the fly
  • Loading branch information
ojeda authored Mar 4, 2022
2 parents 78e2b26 + afba78e commit afa6026
Show file tree
Hide file tree
Showing 17 changed files with 338 additions and 276 deletions.
3 changes: 3 additions & 0 deletions Documentation/kbuild/makefiles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,9 @@ When kbuild executes, the following steps are followed (roughly):

Often, the KBUILD_RUSTFLAGS variable depends on the configuration.

Note that target specification file generation (for ``--target``)
is handled in ``scripts/generate_rust_target.rs``.

KBUILD_AFLAGS_KERNEL
Assembler options specific for built-in

Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
-Werror=return-type -Wno-format-security \
-std=gnu89
KBUILD_CPPFLAGS := -D__KERNEL__
KBUILD_RUST_TARGET := $(srctree)/arch/$(SRCARCH)/rust/target.json
KBUILD_RUSTFLAGS := $(rust_common_flags) \
-Cpanic=abort -Cembed-bitcode=n -Clto=n -Crpath=n \
-Cforce-unwind-tables=n -Ccodegen-units=1 \
Expand Down Expand Up @@ -592,7 +591,7 @@ export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE

export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export KBUILD_RUST_TARGET KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE
export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
Expand Down Expand Up @@ -1578,7 +1577,7 @@ MRPROPER_FILES += include/config include/generated \
certs/x509.genkey \
vmlinux-gdb.py \
*.spec \
rust/libmacros.so
rust/target.json rust/libmacros.so

# clean - Delete most, but leave enough to build external modules
#
Expand Down
27 changes: 0 additions & 27 deletions arch/arm/rust/target.json

This file was deleted.

34 changes: 0 additions & 34 deletions arch/arm64/rust/target.json

This file was deleted.

29 changes: 0 additions & 29 deletions arch/powerpc/rust/target.json

This file was deleted.

1 change: 0 additions & 1 deletion arch/riscv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ riscv-march-$(toolchain-need-zicsr-zifencei) := $(riscv-march-y)_zicsr_zifencei

KBUILD_CFLAGS += -march=$(subst fd,,$(riscv-march-y))
KBUILD_AFLAGS += -march=$(riscv-march-y)
KBUILD_RUST_TARGET := $(srctree)/arch/riscv/rust/$(subst fd,,$(riscv-march-y)).json

KBUILD_CFLAGS += -mno-save-restore
KBUILD_CFLAGS += -DCONFIG_PAGE_OFFSET=$(CONFIG_PAGE_OFFSET)
Expand Down
36 changes: 0 additions & 36 deletions arch/riscv/rust/rv32ima.json

This file was deleted.

36 changes: 0 additions & 36 deletions arch/riscv/rust/rv32imac.json

This file was deleted.

36 changes: 0 additions & 36 deletions arch/riscv/rust/rv64ima.json

This file was deleted.

36 changes: 0 additions & 36 deletions arch/riscv/rust/rv64imac.json

This file was deleted.

36 changes: 0 additions & 36 deletions arch/x86/rust/target.json

This file was deleted.

1 change: 1 addition & 0 deletions rust/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0

target.json
bindings_generated.rs
bindings_helpers_generated.rs
exports_*_generated.h
Expand Down
11 changes: 10 additions & 1 deletion rust/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: GPL-2.0

always-$(CONFIG_RUST) += target.json
no-clean-files += target.json

obj-$(CONFIG_RUST) += core.o compiler_builtins.o
always-$(CONFIG_RUST) += exports_core_generated.h

Expand Down Expand Up @@ -206,6 +209,11 @@ rusttest-kernel: $(srctree)/rust/kernel/lib.rs rusttest-prepare \
$(call if_changed,rustc_test_library)
$(call if_changed,rustdoc_test)

filechk_rust_target = $(objtree)/scripts/generate_rust_target < $<

$(objtree)/rust/target.json: $(objtree)/include/config/auto.conf FORCE
$(call filechk,rust_target)

ifdef CONFIG_CC_IS_CLANG
bindgen_c_flags = $(c_flags)
else
Expand Down Expand Up @@ -364,7 +372,8 @@ $(objtree)/rust/kernel.o: $(srctree)/rust/kernel/lib.rs $(objtree)/rust/alloc.o
$(objtree)/rust/core.o: private skip_clippy = 1
$(objtree)/rust/core.o: private skip_flags = -Dunreachable_pub --edition=2021
$(objtree)/rust/core.o: private rustc_target_flags = $(core-cfgs) --edition=2018
$(objtree)/rust/core.o: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
$(objtree)/rust/core.o: $(RUST_LIB_SRC)/core/src/lib.rs \
$(objtree)/rust/target.json FORCE
$(call if_changed_dep,rustc_library)

rustdoc-core: private rustc_target_flags = $(core-cfgs)
Expand Down
1 change: 1 addition & 0 deletions scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
/asn1_compiler
/bin2c
/generate_rust_target
/insert-sys-cert
/kallsyms
/module.lds
Expand Down
3 changes: 3 additions & 0 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ hostprogs-always-$(CONFIG_BUILDTIME_TABLE_SORT) += sorttable
hostprogs-always-$(CONFIG_ASN1) += asn1_compiler
hostprogs-always-$(CONFIG_MODULE_SIG_FORMAT) += sign-file
hostprogs-always-$(CONFIG_SYSTEM_EXTRA_CERTIFICATE) += insert-sys-cert
hostprogs-always-$(CONFIG_RUST) += generate_rust_target

generate_rust_target-rust := y

HOSTCFLAGS_sorttable.o = -I$(srctree)/tools/include
HOSTLDLIBS_sorttable = -lpthread
Expand Down
2 changes: 1 addition & 1 deletion scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ $(obj)/%.lst: $(src)/%.c FORCE
# Compile Rust sources (.rs)
# ---------------------------------------------------------------------------

rust_cross_flags := --target=$(KBUILD_RUST_TARGET)
rust_cross_flags := --target=$(objtree)/rust/target.json
rust_allowed_features := allocator_api,bench_black_box,concat_idents,generic_associated_types

rust_common_cmd = \
Expand Down
Loading

0 comments on commit afa6026

Please sign in to comment.