Skip to content

Commit ff8e50e

Browse files
committed
replace build.rs with bindgen
1 parent 255713b commit ff8e50e

File tree

5 files changed

+16
-143
lines changed

5 files changed

+16
-143
lines changed

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,9 @@ KBUILD_RUSTCFLAGS :=
513513
# TODO: another option is using explicit target specs, e.g.
514514
# `--target=$(srctree)/arch/$(SRCARCH)/rust-target-spec.json`
515515
KBUILD_CARGOFLAGS := $(CARGO_VERBOSE) --locked \
516-
-Z build-std=core,alloc -Z unstable-options \
517-
--out-dir=out --target=x86_64-linux-kernel
516+
-Z build-std=core,alloc \
517+
-Z unstable-options \
518+
--target=x86_64-linux-kernel
518519
KBUILD_AFLAGS_KERNEL :=
519520
KBUILD_CFLAGS_KERNEL :=
520521
KBUILD_RUSTCFLAGS_KERNEL :=
@@ -728,7 +729,7 @@ $(KCONFIG_CONFIG):
728729
# This exploits the 'multi-target pattern rule' trick.
729730
# The syncconfig should be executed only once to make all the targets.
730731
# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
731-
%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
732+
%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rust_cfg: $(KCONFIG_CONFIG)
732733
$(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
733734
else # !may-sync-config
734735
# External modules and some install targets need include/generated/autoconf.h

rust/kernel/build.rs

-134
This file was deleted.

rust/kernel/src/bindings.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
)]
1010
mod bindings_raw {
1111
use crate::c_types;
12-
include!("bindings_gen.rs");
12+
include!(env!("RUST_BINDGEN_FILE"));
1313
}
1414
pub use bindings_raw::*;
1515

scripts/Makefile.build

+7-3
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,18 @@ $(obj)/%.lst: $(src)/%.c FORCE
307307
# ---------------------------------------------------------------------------
308308

309309
quiet_cmd_cargo = CARGO $(quiet_modtag) $@
310-
cmd_cargo = cd $(src) && $(CARGO) build $(cargo_flags)
310+
cmd_cargo = export RUST_BINDGEN_FILE=$(shell readlink -f rust_bindings.rs) && $(CARGO) build $(cargo_flags) -p $(shell basename $(basename $(src))) --out-dir $(src)
311+
312+
rust_bindings.rs: FORCE
313+
$(Q)$(BINDGEN) $(srctree)/rust/kernel/src/bindings_helper.h --opaque-type xregs_state --opaque-type desc_struct --use-core --ctypes-prefix c_types -o rust_bindings.rs --size_t-is-usize -- $(c_flags)
311314

312315
# The .o from the Rust staticlib
313-
$(obj)/%.o: $(src)/out/lib%.a
316+
#$(obj)/%.o: $(src)/out/lib%.a
317+
$(obj)/%.o: $(obj)/lib%.a
314318
$(Q)$(LD) -r -o $@ --whole-archive $<
315319

316320
# The Rust staticlib from cargo
317-
$(obj)/out/lib%.a: FORCE
321+
$(obj)/lib%.a: FORCE rust_bindings.rs
318322
$(call cmd,cargo)
319323

320324
# Compile assembler sources (.S)

scripts/Makefile.lib

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,11 @@ c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
229229
RUST_BINDGEN_CFLAGS = $(c_flags) $(KBUILD_CFLAGS_MODULE)
230230
export RUST_BINDGEN_CFLAGS
231231

232-
rustc_cfg_flags = $(shell sed -nE 's/^(CONFIG_[^=]+)=(y|m)$$/--cfg \1/p' $(srctree)/include/config/auto.conf | xargs)
232+
KCONFIG_RUSTCONFIG ?= include/generated/rust_cfg
233233

234-
rustc_flags = $(_rustc_flags) $(modkern_rustcflags) $(rustc_cfg_flags)
234+
rustconfig_path = $(shell readlink -f $(KCONFIG_RUSTCONFIG))
235+
236+
rustc_flags = $(_rustc_flags) $(modkern_rustcflags) @$(rustconfig_path)
235237

236238
# Passed by cargo
237239
RUSTFLAGS = $(rustc_flags)

0 commit comments

Comments
 (0)