~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/rust/Makefile

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /rust/Makefile (Version linux-6.12-rc7) and /rust/Makefile (Version linux-6.2.16)


  1 # SPDX-License-Identifier: GPL-2.0                  1 # SPDX-License-Identifier: GPL-2.0
  2                                                     2 
  3 # Where to place rustdoc generated documentati !!   3 always-$(CONFIG_RUST) += target.json
  4 rustdoc_output := $(objtree)/Documentation/out !!   4 no-clean-files += target.json
  5                                                     5 
  6 obj-$(CONFIG_RUST) += core.o compiler_builtins      6 obj-$(CONFIG_RUST) += core.o compiler_builtins.o
  7 always-$(CONFIG_RUST) += exports_core_generate      7 always-$(CONFIG_RUST) += exports_core_generated.h
  8                                                     8 
  9 # Missing prototypes are expected in the helpe      9 # Missing prototypes are expected in the helpers since these are exported
 10 # for Rust only, thus there is no header nor p     10 # for Rust only, thus there is no header nor prototypes.
 11 obj-$(CONFIG_RUST) += helpers/helpers.o        !!  11 obj-$(CONFIG_RUST) += helpers.o
 12 CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-pr !!  12 CFLAGS_REMOVE_helpers.o = -Wmissing-prototypes -Wmissing-declarations
 13                                                    13 
 14 always-$(CONFIG_RUST) += libmacros.so              14 always-$(CONFIG_RUST) += libmacros.so
 15 no-clean-files += libmacros.so                     15 no-clean-files += libmacros.so
 16                                                    16 
 17 always-$(CONFIG_RUST) += bindings/bindings_gen     17 always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
 18 obj-$(CONFIG_RUST) += alloc.o bindings.o kerne     18 obj-$(CONFIG_RUST) += alloc.o bindings.o kernel.o
 19 always-$(CONFIG_RUST) += exports_alloc_generat !!  19 always-$(CONFIG_RUST) += exports_alloc_generated.h exports_bindings_generated.h \
 20     exports_bindings_generated.h exports_kerne !!  20     exports_kernel_generated.h
 21                                                << 
 22 always-$(CONFIG_RUST) += uapi/uapi_generated.r << 
 23 obj-$(CONFIG_RUST) += uapi.o                   << 
 24                                                    21 
 25 ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW               22 ifdef CONFIG_RUST_BUILD_ASSERT_ALLOW
 26 obj-$(CONFIG_RUST) += build_error.o                23 obj-$(CONFIG_RUST) += build_error.o
 27 else                                               24 else
 28 always-$(CONFIG_RUST) += build_error.o             25 always-$(CONFIG_RUST) += build_error.o
 29 endif                                              26 endif
 30                                                    27 
 31 obj-$(CONFIG_RUST) += exports.o                    28 obj-$(CONFIG_RUST) += exports.o
 32                                                    29 
 33 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += docte << 
 34 always-$(CONFIG_RUST_KERNEL_DOCTESTS) += docte << 
 35                                                << 
 36 obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests << 
 37 obj-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests << 
 38                                                << 
 39 # Avoids running `$(RUSTC)` for the sysroot wh     30 # Avoids running `$(RUSTC)` for the sysroot when it may not be available.
 40 ifdef CONFIG_RUST                                  31 ifdef CONFIG_RUST
 41                                                    32 
 42 # `$(rust_flags)` is passed in case the user a     33 # `$(rust_flags)` is passed in case the user added `--sysroot`.
 43 rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $ !!  34 rustc_sysroot := $(shell $(RUSTC) $(rust_flags) --print sysroot)
 44 rustc_host_target := $(shell $(RUSTC) --versio     35 rustc_host_target := $(shell $(RUSTC) --version --verbose | grep -F 'host: ' | cut -d' ' -f2)
 45 RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/s     36 RUST_LIB_SRC ?= $(rustc_sysroot)/lib/rustlib/src/rust/library
 46                                                    37 
 47 ifneq ($(quiet),)                              !!  38 ifeq ($(quiet),silent_)
                                                   >>  39 cargo_quiet=-q
                                                   >>  40 rust_test_quiet=-q
                                                   >>  41 rustdoc_test_quiet=--test-args -q
                                                   >>  42 else ifeq ($(quiet),quiet_)
 48 rust_test_quiet=-q                                 43 rust_test_quiet=-q
 49 rustdoc_test_quiet=--test-args -q                  44 rustdoc_test_quiet=--test-args -q
 50 rustdoc_test_kernel_quiet=>/dev/null           !!  45 else
                                                   >>  46 cargo_quiet=--verbose
 51 endif                                              47 endif
 52                                                    48 
 53 core-cfgs = \                                      49 core-cfgs = \
 54     --cfg no_fp_fmt_parse                          50     --cfg no_fp_fmt_parse
 55                                                    51 
 56 alloc-cfgs = \                                     52 alloc-cfgs = \
                                                   >>  53     --cfg no_fmt \
 57     --cfg no_global_oom_handling \                 54     --cfg no_global_oom_handling \
                                                   >>  55     --cfg no_macros \
 58     --cfg no_rc \                                  56     --cfg no_rc \
 59     --cfg no_sync                              !!  57     --cfg no_str \
                                                   >>  58     --cfg no_string \
                                                   >>  59     --cfg no_sync \
                                                   >>  60     --cfg no_thin
 60                                                    61 
 61 quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_hos     62 quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
 62       cmd_rustdoc = \                              63       cmd_rustdoc = \
 63         OBJTREE=$(abspath $(objtree)) \            64         OBJTREE=$(abspath $(objtree)) \
 64         $(RUSTDOC) $(if $(rustdoc_host),$(rust     65         $(RUSTDOC) $(if $(rustdoc_host),$(rust_common_flags),$(rust_flags)) \
 65                 $(rustc_target_flags) -L$(objt     66                 $(rustc_target_flags) -L$(objtree)/$(obj) \
 66                 -Zunstable-options --generate- !!  67                 --output $(objtree)/$(obj)/doc \
 67                 --output $(rustdoc_output) \   << 
 68                 --crate-name $(subst rustdoc-,     68                 --crate-name $(subst rustdoc-,,$@) \
 69                 $(if $(rustdoc_host),,--sysroo << 
 70                 @$(objtree)/include/generated/     69                 @$(objtree)/include/generated/rustc_cfg $<
 71                                                    70 
 72 # The `html_logo_url` and `html_favicon_url` f     71 # The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
 73 # can be used to specify a custom logo. Howeve     72 # can be used to specify a custom logo. However:
 74 #   - The given value is used as-is, thus it c     73 #   - The given value is used as-is, thus it cannot be relative or a local file
 75 #     (unlike the non-custom case) since the g     74 #     (unlike the non-custom case) since the generated docs have subfolders.
 76 #   - It requires adding it to every crate.        75 #   - It requires adding it to every crate.
 77 #   - It requires changing `core` which comes      76 #   - It requires changing `core` which comes from the sysroot.
 78 #                                                  77 #
 79 # Using `-Zcrate-attr` would solve the last tw     78 # Using `-Zcrate-attr` would solve the last two points, but not the first.
 80 # The https://github.com/rust-lang/rfcs/pull/3     79 # The https://github.com/rust-lang/rfcs/pull/3226 RFC suggests two new
 81 # command-like flags to solve the issue. Meanw     80 # command-like flags to solve the issue. Meanwhile, we use the non-custom case
 82 # and then retouch the generated files.            81 # and then retouch the generated files.
 83 rustdoc: rustdoc-core rustdoc-macros rustdoc-c     82 rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
 84     rustdoc-alloc rustdoc-kernel                   83     rustdoc-alloc rustdoc-kernel
 85         $(Q)cp $(srctree)/Documentation/images !!  84         $(Q)cp $(srctree)/Documentation/images/logo.svg $(objtree)/$(obj)/doc
 86         $(Q)cp $(srctree)/Documentation/images !!  85         $(Q)cp $(srctree)/Documentation/images/COPYING-logo $(objtree)/$(obj)/doc
 87         $(Q)find $(rustdoc_output) -name '*.ht !!  86         $(Q)find $(objtree)/$(obj)/doc -name '*.html' -type f -print0 | xargs -0 sed -Ei \
 88                 -e 's:rust-logo-[0-9a-f]+\.svg !!  87                 -e 's:rust-logo\.svg:logo.svg:g' \
 89                 -e 's:favicon-[0-9a-f]+\.svg:l !!  88                 -e 's:rust-logo\.png:logo.svg:g' \
 90                 -e 's:<link rel="alternate ico !!  89                 -e 's:favicon\.svg:logo.svg:g' \
 91                 -e 's:<a href="srctree/([^"]+) !!  90                 -e 's:<link rel="alternate icon" type="image/png" href="[./]*favicon-(16x16|32x32)\.png">::g'
 92         $(Q)for f in $(rustdoc_output)/static. !!  91         $(Q)echo '.logo-container > img { object-fit: contain; }' \
 93                 echo ".logo-container > img {  !!  92                 >> $(objtree)/$(obj)/doc/rustdoc.css
 94                                                    93 
 95 rustdoc-macros: private rustdoc_host = yes         94 rustdoc-macros: private rustdoc_host = yes
 96 rustdoc-macros: private rustc_target_flags = -     95 rustdoc-macros: private rustc_target_flags = --crate-type proc-macro \
 97     --extern proc_macro                            96     --extern proc_macro
 98 rustdoc-macros: $(src)/macros/lib.rs FORCE         97 rustdoc-macros: $(src)/macros/lib.rs FORCE
 99         +$(call if_changed,rustdoc)            !!  98         $(call if_changed,rustdoc)
100                                                    99 
101 rustdoc-core: private rustc_target_flags = $(c    100 rustdoc-core: private rustc_target_flags = $(core-cfgs)
102 rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs     101 rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs FORCE
103         +$(call if_changed,rustdoc)            !! 102         $(call if_changed,rustdoc)
104                                                   103 
105 rustdoc-compiler_builtins: $(src)/compiler_bui    104 rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
106         +$(call if_changed,rustdoc)            !! 105         $(call if_changed,rustdoc)
107                                                   106 
108 # We need to allow `rustdoc::broken_intra_doc_    107 # We need to allow `rustdoc::broken_intra_doc_links` because some
109 # `no_global_oom_handling` functions refer to     108 # `no_global_oom_handling` functions refer to non-`no_global_oom_handling`
110 # functions. Ideally `rustdoc` would have a wa    109 # functions. Ideally `rustdoc` would have a way to distinguish broken links
111 # due to things that are "configured out" vs.     110 # due to things that are "configured out" vs. entirely non-existing ones.
112 rustdoc-alloc: private rustc_target_flags = $(    111 rustdoc-alloc: private rustc_target_flags = $(alloc-cfgs) \
113     -Arustdoc::broken_intra_doc_links             112     -Arustdoc::broken_intra_doc_links
114 rustdoc-alloc: $(RUST_LIB_SRC)/alloc/src/lib.r !! 113 rustdoc-alloc: $(src)/alloc/lib.rs rustdoc-core rustdoc-compiler_builtins FORCE
115         +$(call if_changed,rustdoc)            !! 114         $(call if_changed,rustdoc)
116                                                   115 
117 rustdoc-kernel: private rustc_target_flags = -    116 rustdoc-kernel: private rustc_target_flags = --extern alloc \
118     --extern build_error --extern macros=$(obj    117     --extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
119     --extern bindings --extern uapi            !! 118     --extern bindings
120 rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-c    119 rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-macros \
121     rustdoc-compiler_builtins rustdoc-alloc $(    120     rustdoc-compiler_builtins rustdoc-alloc $(obj)/libmacros.so \
122     $(obj)/bindings.o FORCE                       121     $(obj)/bindings.o FORCE
123         +$(call if_changed,rustdoc)            !! 122         $(call if_changed,rustdoc)
124                                                   123 
125 quiet_cmd_rustc_test_library = RUSTC TL $<        124 quiet_cmd_rustc_test_library = RUSTC TL $<
126       cmd_rustc_test_library = \                  125       cmd_rustc_test_library = \
127         OBJTREE=$(abspath $(objtree)) \           126         OBJTREE=$(abspath $(objtree)) \
128         $(RUSTC) $(rust_common_flags) \           127         $(RUSTC) $(rust_common_flags) \
129                 @$(objtree)/include/generated/    128                 @$(objtree)/include/generated/rustc_cfg $(rustc_target_flags) \
130                 --crate-type $(if $(rustc_test    129                 --crate-type $(if $(rustc_test_library_proc),proc-macro,rlib) \
131                 --out-dir $(objtree)/$(obj)/te    130                 --out-dir $(objtree)/$(obj)/test --cfg testlib \
                                                   >> 131                 --sysroot $(objtree)/$(obj)/test/sysroot \
132                 -L$(objtree)/$(obj)/test \        132                 -L$(objtree)/$(obj)/test \
133                 --crate-name $(subst rusttest-    133                 --crate-name $(subst rusttest-,,$(subst rusttestlib-,,$@)) $<
134                                                   134 
135 rusttestlib-build_error: $(src)/build_error.rs !! 135 rusttestlib-build_error: $(src)/build_error.rs rusttest-prepare FORCE
136         +$(call if_changed,rustc_test_library) !! 136         $(call if_changed,rustc_test_library)
137                                                   137 
138 rusttestlib-macros: private rustc_target_flags    138 rusttestlib-macros: private rustc_target_flags = --extern proc_macro
139 rusttestlib-macros: private rustc_test_library    139 rusttestlib-macros: private rustc_test_library_proc = yes
140 rusttestlib-macros: $(src)/macros/lib.rs FORCE !! 140 rusttestlib-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
141         +$(call if_changed,rustc_test_library) !! 141         $(call if_changed,rustc_test_library)
142                                                   142 
143 rusttestlib-bindings: $(src)/bindings/lib.rs F !! 143 rusttestlib-bindings: $(src)/bindings/lib.rs rusttest-prepare FORCE
144         +$(call if_changed,rustc_test_library) !! 144         $(call if_changed,rustc_test_library)
145                                                << 
146 rusttestlib-uapi: $(src)/uapi/lib.rs FORCE     << 
147         +$(call if_changed,rustc_test_library) << 
148                                                   145 
149 quiet_cmd_rustdoc_test = RUSTDOC T $<             146 quiet_cmd_rustdoc_test = RUSTDOC T $<
150       cmd_rustdoc_test = \                        147       cmd_rustdoc_test = \
151         OBJTREE=$(abspath $(objtree)) \           148         OBJTREE=$(abspath $(objtree)) \
152         $(RUSTDOC) --test $(rust_common_flags)    149         $(RUSTDOC) --test $(rust_common_flags) \
153                 @$(objtree)/include/generated/    150                 @$(objtree)/include/generated/rustc_cfg \
154                 $(rustc_target_flags) $(rustdo    151                 $(rustc_target_flags) $(rustdoc_test_target_flags) \
155                 $(rustdoc_test_quiet) \        !! 152                 --sysroot $(objtree)/$(obj)/test/sysroot $(rustdoc_test_quiet) \
156                 -L$(objtree)/$(obj)/test --out !! 153                 -L$(objtree)/$(obj)/test --output $(objtree)/$(obj)/doc \
157                 --crate-name $(subst rusttest-    154                 --crate-name $(subst rusttest-,,$@) $<
158                                                   155 
159 quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<  << 
160       cmd_rustdoc_test_kernel = \              << 
161         rm -rf $(objtree)/$(obj)/test/doctests << 
162         mkdir -p $(objtree)/$(obj)/test/doctes << 
163         OBJTREE=$(abspath $(objtree)) \        << 
164         $(RUSTDOC) --test $(rust_flags) \      << 
165                 -L$(objtree)/$(obj) --extern a << 
166                 --extern build_error --extern  << 
167                 --extern bindings --extern uap << 
168                 --no-run --crate-name kernel - << 
169                 --sysroot=/dev/null \          << 
170                 --test-builder $(objtree)/scri << 
171                 $< $(rustdoc_test_kernel_quiet << 
172         $(objtree)/scripts/rustdoc_test_gen    << 
173                                                << 
174 %/doctests_kernel_generated.rs %/doctests_kern << 
175     $(src)/kernel/lib.rs $(obj)/kernel.o \     << 
176     $(objtree)/scripts/rustdoc_test_builder \  << 
177     $(objtree)/scripts/rustdoc_test_gen FORCE  << 
178         +$(call if_changed,rustdoc_test_kernel << 
179                                                << 
180 # We cannot use `-Zpanic-abort-tests` because     156 # We cannot use `-Zpanic-abort-tests` because some tests are dynamic,
181 # so for the moment we skip `-Cpanic=abort`.      157 # so for the moment we skip `-Cpanic=abort`.
182 quiet_cmd_rustc_test = RUSTC T  $<                158 quiet_cmd_rustc_test = RUSTC T  $<
183       cmd_rustc_test = \                          159       cmd_rustc_test = \
184         OBJTREE=$(abspath $(objtree)) \           160         OBJTREE=$(abspath $(objtree)) \
185         $(RUSTC) --test $(rust_common_flags) \    161         $(RUSTC) --test $(rust_common_flags) \
186                 @$(objtree)/include/generated/    162                 @$(objtree)/include/generated/rustc_cfg \
187                 $(rustc_target_flags) --out-di    163                 $(rustc_target_flags) --out-dir $(objtree)/$(obj)/test \
                                                   >> 164                 --sysroot $(objtree)/$(obj)/test/sysroot \
188                 -L$(objtree)/$(obj)/test \        165                 -L$(objtree)/$(obj)/test \
189                 --crate-name $(subst rusttest-    166                 --crate-name $(subst rusttest-,,$@) $<; \
190         $(objtree)/$(obj)/test/$(subst rusttes    167         $(objtree)/$(obj)/test/$(subst rusttest-,,$@) $(rust_test_quiet) \
191                 $(rustc_test_run_flags)           168                 $(rustc_test_run_flags)
192                                                   169 
193 rusttest: rusttest-macros rusttest-kernel         170 rusttest: rusttest-macros rusttest-kernel
194                                                   171 
                                                   >> 172 # This prepares a custom sysroot with our custom `alloc` instead of
                                                   >> 173 # the standard one.
                                                   >> 174 #
                                                   >> 175 # This requires several hacks:
                                                   >> 176 #   - Unlike `core` and `alloc`, `std` depends on more than a dozen crates,
                                                   >> 177 #     including third-party crates that need to be downloaded, plus custom
                                                   >> 178 #     `build.rs` steps. Thus hardcoding things here is not maintainable.
                                                   >> 179 #   - `cargo` knows how to build the standard library, but it is an unstable
                                                   >> 180 #     feature so far (`-Zbuild-std`).
                                                   >> 181 #   - `cargo` only considers the use case of building the standard library
                                                   >> 182 #     to use it in a given package. Thus we need to create a dummy package
                                                   >> 183 #     and pick the generated libraries from there.
                                                   >> 184 #   - Since we only keep a subset of upstream `alloc` in-tree, we need
                                                   >> 185 #     to recreate it on the fly by putting our sources on top.
                                                   >> 186 #   - The usual ways of modifying the dependency graph in `cargo` do not seem
                                                   >> 187 #     to apply for the `-Zbuild-std` steps, thus we have to mislead it
                                                   >> 188 #     by modifying the sources in the sysroot.
                                                   >> 189 #   - To avoid messing with the user's Rust installation, we create a clone
                                                   >> 190 #     of the sysroot. However, `cargo` ignores `RUSTFLAGS` in the `-Zbuild-std`
                                                   >> 191 #     steps, thus we use a wrapper binary passed via `RUSTC` to pass the flag.
                                                   >> 192 #
                                                   >> 193 # In the future, we hope to avoid the whole ordeal by either:
                                                   >> 194 #   - Making the `test` crate not depend on `std` (either improving upstream
                                                   >> 195 #     or having our own custom crate).
                                                   >> 196 #   - Making the tests run in kernel space (requires the previous point).
                                                   >> 197 #   - Making `std` and friends be more like a "normal" crate, so that
                                                   >> 198 #     `-Zbuild-std` and related hacks are not needed.
                                                   >> 199 quiet_cmd_rustsysroot = RUSTSYSROOT
                                                   >> 200       cmd_rustsysroot = \
                                                   >> 201         rm -rf $(objtree)/$(obj)/test; \
                                                   >> 202         mkdir -p $(objtree)/$(obj)/test; \
                                                   >> 203         cp -a $(rustc_sysroot) $(objtree)/$(obj)/test/sysroot; \
                                                   >> 204         cp -r $(srctree)/$(src)/alloc/* \
                                                   >> 205                 $(objtree)/$(obj)/test/sysroot/lib/rustlib/src/rust/library/alloc/src; \
                                                   >> 206         echo '\#!/bin/sh' > $(objtree)/$(obj)/test/rustc_sysroot; \
                                                   >> 207         echo "$(RUSTC) --sysroot=$(abspath $(objtree)/$(obj)/test/sysroot) \"\$$@\"" \
                                                   >> 208                 >> $(objtree)/$(obj)/test/rustc_sysroot; \
                                                   >> 209         chmod u+x $(objtree)/$(obj)/test/rustc_sysroot; \
                                                   >> 210         $(CARGO) -q new $(objtree)/$(obj)/test/dummy; \
                                                   >> 211         RUSTC=$(objtree)/$(obj)/test/rustc_sysroot $(CARGO) $(cargo_quiet) \
                                                   >> 212                 test -Zbuild-std --target $(rustc_host_target) \
                                                   >> 213                 --manifest-path $(objtree)/$(obj)/test/dummy/Cargo.toml; \
                                                   >> 214         rm $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib/*; \
                                                   >> 215         cp $(objtree)/$(obj)/test/dummy/target/$(rustc_host_target)/debug/deps/* \
                                                   >> 216                 $(objtree)/$(obj)/test/sysroot/lib/rustlib/$(rustc_host_target)/lib
                                                   >> 217 
                                                   >> 218 rusttest-prepare: FORCE
                                                   >> 219         $(call if_changed,rustsysroot)
                                                   >> 220 
195 rusttest-macros: private rustc_target_flags =     221 rusttest-macros: private rustc_target_flags = --extern proc_macro
196 rusttest-macros: private rustdoc_test_target_f    222 rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
197 rusttest-macros: $(src)/macros/lib.rs FORCE    !! 223 rusttest-macros: $(src)/macros/lib.rs rusttest-prepare FORCE
198         +$(call if_changed,rustc_test)         !! 224         $(call if_changed,rustc_test)
199         +$(call if_changed,rustdoc_test)       !! 225         $(call if_changed,rustdoc_test)
200                                                   226 
201 rusttest-kernel: private rustc_target_flags =     227 rusttest-kernel: private rustc_target_flags = --extern alloc \
202     --extern build_error --extern macros --ext !! 228     --extern build_error --extern macros --extern bindings
203 rusttest-kernel: $(src)/kernel/lib.rs \        !! 229 rusttest-kernel: $(src)/kernel/lib.rs rusttest-prepare \
204     rusttestlib-build_error rusttestlib-macros !! 230     rusttestlib-build_error rusttestlib-macros rusttestlib-bindings FORCE
205     rusttestlib-uapi FORCE                     !! 231         $(call if_changed,rustc_test)
206         +$(call if_changed,rustc_test)         !! 232         $(call if_changed,rustc_test_library)
207         +$(call if_changed,rustc_test_library) !! 233 
                                                   >> 234 filechk_rust_target = $(objtree)/scripts/generate_rust_target < $<
                                                   >> 235 
                                                   >> 236 $(obj)/target.json: $(objtree)/include/config/auto.conf FORCE
                                                   >> 237         $(call filechk,rust_target)
208                                                   238 
209 ifdef CONFIG_CC_IS_CLANG                          239 ifdef CONFIG_CC_IS_CLANG
210 bindgen_c_flags = $(c_flags)                      240 bindgen_c_flags = $(c_flags)
211 else                                              241 else
212 # bindgen relies on libclang to parse C. Ideal    242 # bindgen relies on libclang to parse C. Ideally, bindgen would support a GCC
213 # plugin backend and/or the Clang driver would    243 # plugin backend and/or the Clang driver would be perfectly compatible with GCC.
214 #                                                 244 #
215 # For the moment, here we are tweaking the fla    245 # For the moment, here we are tweaking the flags on the fly. This is a hack,
216 # and some kernel configurations may not work     246 # and some kernel configurations may not work (e.g. `GCC_PLUGIN_RANDSTRUCT`
217 # if we end up using one of those structs).       247 # if we end up using one of those structs).
218 bindgen_skip_c_flags := -mno-fp-ret-in-387 -mp    248 bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
219         -mskip-rax-setup -mgeneral-regs-only -    249         -mskip-rax-setup -mgeneral-regs-only -msign-return-address=% \
220         -mindirect-branch=thunk-extern -mindir    250         -mindirect-branch=thunk-extern -mindirect-branch-register \
221         -mfunction-return=thunk-extern -mrecor    251         -mfunction-return=thunk-extern -mrecord-mcount -mabi=lp64 \
222         -mindirect-branch-cs-prefix -mstack-pr    252         -mindirect-branch-cs-prefix -mstack-protector-guard% -mtraceback=no \
223         -mno-pointers-to-nested-functions -mno    253         -mno-pointers-to-nested-functions -mno-string \
224         -mno-strict-align -mstrict-align \        254         -mno-strict-align -mstrict-align \
225         -fconserve-stack -falign-jumps=% -fali    255         -fconserve-stack -falign-jumps=% -falign-loops=% \
226         -femit-struct-debug-baseonly -fno-ipa-    256         -femit-struct-debug-baseonly -fno-ipa-cp-clone -fno-ipa-sra \
227         -fno-partial-inlining -fplugin-arg-arm    257         -fno-partial-inlining -fplugin-arg-arm_ssp_per_task_plugin-% \
228         -fno-reorder-blocks -fno-allow-store-d    258         -fno-reorder-blocks -fno-allow-store-data-races -fasan-shadow-offset=% \
229         -fzero-call-used-regs=% -fno-stack-cla    259         -fzero-call-used-regs=% -fno-stack-clash-protection \
230         -fno-inline-functions-called-once -fsa !! 260         -fno-inline-functions-called-once \
231         -fstrict-flex-arrays=% -fmin-function- << 
232         --param=% --param asan-%                  261         --param=% --param asan-%
233                                                   262 
234 # Derived from `scripts/Makefile.clang`.          263 # Derived from `scripts/Makefile.clang`.
235 BINDGEN_TARGET_x86      := x86_64-linux-gnu       264 BINDGEN_TARGET_x86      := x86_64-linux-gnu
236 BINDGEN_TARGET_arm64    := aarch64-linux-gnu   << 
237 BINDGEN_TARGET          := $(BINDGEN_TARGET_$(    265 BINDGEN_TARGET          := $(BINDGEN_TARGET_$(SRCARCH))
238                                                   266 
239 # All warnings are inhibited since GCC builds     267 # All warnings are inhibited since GCC builds are very experimental,
240 # many GCC warnings are not supported by Clang    268 # many GCC warnings are not supported by Clang, they may only appear in
241 # some configurations, with new GCC versions,     269 # some configurations, with new GCC versions, etc.
242 bindgen_extra_c_flags = -w --target=$(BINDGEN_    270 bindgen_extra_c_flags = -w --target=$(BINDGEN_TARGET)
243                                                   271 
244 # Auto variable zero-initialization requires a << 
245 # clang that is going to be removed sometime i << 
246 # clang-18), so make sure to pass this option  << 
247 # (libclang major version < 16).               << 
248 #                                              << 
249 # https://github.com/llvm/llvm-project/issues/ << 
250 # https://github.com/llvm/llvm-project/blob/ll << 
251 ifdef CONFIG_INIT_STACK_ALL_ZERO               << 
252 libclang_maj_ver=$(shell $(BINDGEN) $(srctree) << 
253 ifeq ($(shell expr $(libclang_maj_ver) \< 16), << 
254 bindgen_extra_c_flags += -enable-trivial-auto- << 
255 endif                                          << 
256 endif                                          << 
257                                                << 
258 bindgen_c_flags = $(filter-out $(bindgen_skip_    272 bindgen_c_flags = $(filter-out $(bindgen_skip_c_flags), $(c_flags)) \
259         $(bindgen_extra_c_flags)                  273         $(bindgen_extra_c_flags)
260 endif                                             274 endif
261                                                   275 
262 ifdef CONFIG_LTO                                  276 ifdef CONFIG_LTO
263 bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_    277 bindgen_c_flags_lto = $(filter-out $(CC_FLAGS_LTO), $(bindgen_c_flags))
264 else                                              278 else
265 bindgen_c_flags_lto = $(bindgen_c_flags)          279 bindgen_c_flags_lto = $(bindgen_c_flags)
266 endif                                             280 endif
267                                                   281 
268 bindgen_c_flags_final = $(bindgen_c_flags_lto)    282 bindgen_c_flags_final = $(bindgen_c_flags_lto) -D__BINDGEN__
269                                                   283 
270 quiet_cmd_bindgen = BINDGEN $@                    284 quiet_cmd_bindgen = BINDGEN $@
271       cmd_bindgen = \                             285       cmd_bindgen = \
272         $(BINDGEN) $< $(bindgen_target_flags)     286         $(BINDGEN) $< $(bindgen_target_flags) \
273                 --use-core --with-derive-defau    287                 --use-core --with-derive-default --ctypes-prefix core::ffi --no-layout-tests \
274                 --no-debug '.*' --enable-funct !! 288                 --no-debug '.*' \
275                 -o $@ -- $(bindgen_c_flags_fin !! 289                 --size_t-is-usize -o $@ -- $(bindgen_c_flags_final) -DMODULE \
276                 $(bindgen_target_cflags) $(bin    290                 $(bindgen_target_cflags) $(bindgen_target_extra)
277                                                   291 
278 $(obj)/bindings/bindings_generated.rs: private    292 $(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
279     $(shell grep -Ev '^#|^$$' $(src)/bindgen_p !! 293     $(shell grep -v '^\#\|^$$' $(srctree)/$(src)/bindgen_parameters)
280 $(obj)/bindings/bindings_generated.rs: private << 
281     sed -Ei 's/pub const RUST_CONST_HELPER_([a << 
282 $(obj)/bindings/bindings_generated.rs: $(src)/    294 $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
283     $(src)/bindgen_parameters FORCE               295     $(src)/bindgen_parameters FORCE
284         $(call if_changed_dep,bindgen)            296         $(call if_changed_dep,bindgen)
285                                                   297 
286 $(obj)/uapi/uapi_generated.rs: private bindgen << 
287     $(shell grep -Ev '^#|^$$' $(src)/bindgen_p << 
288 $(obj)/uapi/uapi_generated.rs: $(src)/uapi/uap << 
289     $(src)/bindgen_parameters FORCE            << 
290         $(call if_changed_dep,bindgen)         << 
291                                                << 
292 # See `CFLAGS_REMOVE_helpers.o` above. In addi    298 # See `CFLAGS_REMOVE_helpers.o` above. In addition, Clang on C does not warn
293 # with `-Wmissing-declarations` (unlike GCC),     299 # with `-Wmissing-declarations` (unlike GCC), so it is not strictly needed here
294 # given it is `libclang`; but for consistency,    300 # given it is `libclang`; but for consistency, future Clang changes and/or
295 # a potential future GCC backend for `bindgen`    301 # a potential future GCC backend for `bindgen`, we disable it too.
296 $(obj)/bindings/bindings_helpers_generated.rs:    302 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
297     --blocklist-type '.*' --allowlist-var '' \ !! 303     --blacklist-type '.*' --whitelist-var '' \
298     --allowlist-function 'rust_helper_.*'      !! 304     --whitelist-function 'rust_helper_.*'
299 $(obj)/bindings/bindings_helpers_generated.rs:    305 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
300     -I$(objtree)/$(obj) -Wno-missing-prototype    306     -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
301 $(obj)/bindings/bindings_helpers_generated.rs:    307 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
302     sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_    308     sed -Ei 's/pub fn rust_helper_([a-zA-Z0-9_]*)/#[link_name="rust_helper_\1"]\n    pub fn \1/g' $@
303 $(obj)/bindings/bindings_helpers_generated.rs: !! 309 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE
304         $(call if_changed_dep,bindgen)            310         $(call if_changed_dep,bindgen)
305                                                   311 
306 quiet_cmd_exports = EXPORTS $@                    312 quiet_cmd_exports = EXPORTS $@
307       cmd_exports = \                             313       cmd_exports = \
308         $(NM) -p --defined-only $< \              314         $(NM) -p --defined-only $< \
309                 | awk '$$2~/(T|R|D|B)/ && $$3! !! 315                 | grep -E ' (T|R|D) ' | cut -d ' ' -f 3 \
                                                   >> 316                 | xargs -Isymbol \
                                                   >> 317                 echo 'EXPORT_SYMBOL_RUST_GPL(symbol);' > $@
310                                                   318 
311 $(obj)/exports_core_generated.h: $(obj)/core.o    319 $(obj)/exports_core_generated.h: $(obj)/core.o FORCE
312         $(call if_changed,exports)                320         $(call if_changed,exports)
313                                                   321 
314 $(obj)/exports_alloc_generated.h: $(obj)/alloc    322 $(obj)/exports_alloc_generated.h: $(obj)/alloc.o FORCE
315         $(call if_changed,exports)                323         $(call if_changed,exports)
316                                                   324 
317 # Even though Rust kernel modules should never << 
318 # symbols from the `bindings` crate and the C  << 
319 # because Rust generics and inlined functions  << 
320 # in the crate where they are defined. Other h << 
321 # functions, may not be exported, in principle << 
322 # compiler does not guarantee codegen will be  << 
323 # function either. Therefore, we export all sy << 
324 # In the future, this may be revisited to redu << 
325 # the compiler is informed about the places co << 
326 $(obj)/exports_helpers_generated.h: $(obj)/hel << 
327         $(call if_changed,exports)             << 
328                                                << 
329 $(obj)/exports_bindings_generated.h: $(obj)/bi    325 $(obj)/exports_bindings_generated.h: $(obj)/bindings.o FORCE
330         $(call if_changed,exports)                326         $(call if_changed,exports)
331                                                   327 
332 $(obj)/exports_kernel_generated.h: $(obj)/kern    328 $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
333         $(call if_changed,exports)                329         $(call if_changed,exports)
334                                                   330 
335 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_    331 quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
336       cmd_rustc_procmacro = \                     332       cmd_rustc_procmacro = \
337         $(RUSTC_OR_CLIPPY) $(rust_common_flags    333         $(RUSTC_OR_CLIPPY) $(rust_common_flags) \
338                 -Clinker-flavor=gcc -Clinker=$ !! 334                 --emit=dep-info,link --extern proc_macro \
339                 -Clink-args='$(call escsq,$(KB !! 335                 --crate-type proc-macro --out-dir $(objtree)/$(obj) \
340                 --emit=dep-info=$(depfile) --e !! 336                 --crate-name $(patsubst lib%.so,%,$(notdir $@)) $<; \
341                 --crate-type proc-macro \      !! 337         mv $(objtree)/$(obj)/$(patsubst lib%.so,%,$(notdir $@)).d $(depfile); \
342                 --crate-name $(patsubst lib%.s !! 338         sed -i '/^\#/d' $(depfile)
343                                                   339 
344 # Procedural macros can only be used with the     340 # Procedural macros can only be used with the `rustc` that compiled it.
345 $(obj)/libmacros.so: $(src)/macros/lib.rs FORC !! 341 # Therefore, to get `libmacros.so` automatically recompiled when the compiler
346         +$(call if_changed_dep,rustc_procmacro !! 342 # version changes, we add `core.o` as a dependency (even if it is not needed).
                                                   >> 343 $(obj)/libmacros.so: $(src)/macros/lib.rs $(obj)/core.o FORCE
                                                   >> 344         $(call if_changed_dep,rustc_procmacro)
347                                                   345 
348 quiet_cmd_rustc_library = $(if $(skip_clippy),    346 quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
349       cmd_rustc_library = \                       347       cmd_rustc_library = \
350         OBJTREE=$(abspath $(objtree)) \           348         OBJTREE=$(abspath $(objtree)) \
351         $(if $(skip_clippy),$(RUSTC),$(RUSTC_O    349         $(if $(skip_clippy),$(RUSTC),$(RUSTC_OR_CLIPPY)) \
352                 $(filter-out $(skip_flags),$(r    350                 $(filter-out $(skip_flags),$(rust_flags) $(rustc_target_flags)) \
353                 --emit=dep-info=$(depfile) --e !! 351                 --emit=dep-info,obj,metadata --crate-type rlib \
354                 --emit=metadata=$(dir $@)$(pat !! 352                 --out-dir $(objtree)/$(obj) -L$(objtree)/$(obj) \
355                 --crate-type rlib -L$(objtree) !! 353                 --crate-name $(patsubst %.o,%,$(notdir $@)) $<; \
356                 --crate-name $(patsubst %.o,%, !! 354         mv $(objtree)/$(obj)/$(patsubst %.o,%,$(notdir $@)).d $(depfile); \
357                 --sysroot=/dev/null \          !! 355         sed -i '/^\#/d' $(depfile) \
358         $(if $(rustc_objcopy),;$(OBJCOPY) $(ru !! 356         $(if $(rustc_objcopy),;$(OBJCOPY) $(rustc_objcopy) $@)
359         $(cmd_objtool)                         << 
360                                                   357 
361 rust-analyzer:                                    358 rust-analyzer:
362         $(Q)$(srctree)/scripts/generate_rust_a !! 359         $(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \
363                 --cfgs='core=$(core-cfgs)' --c !! 360                 $(RUST_LIB_SRC) > $(objtree)/rust-project.json
364                 $(realpath $(srctree)) $(realp << 
365                 $(rustc_sysroot) $(RUST_LIB_SR << 
366                 $(if $(KBUILD_EXTMOD),$(extmod << 
367                                                << 
368 redirect-intrinsics = \                        << 
369         __addsf3 __eqsf2 __extendsfdf2 __gesf2 << 
370         __adddf3 __eqdf2 __ledf2 __ltdf2 __mul << 
371         __muloti4 __multi3 \                   << 
372         __udivmodti4 __udivti3 __umodti3       << 
373                                                << 
374 ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RIS << 
375         # These intrinsics are defined for ARM << 
376         redirect-intrinsics += \               << 
377                 __ashrti3 \                    << 
378                 __ashlti3 __lshrti3            << 
379 endif                                          << 
380                                                << 
381 define rule_rustc_library                      << 
382         $(call cmd_and_fixdep,rustc_library)   << 
383         $(call cmd,gen_objtooldep)             << 
384 endef                                          << 
385                                                   361 
386 $(obj)/core.o: private skip_clippy = 1            362 $(obj)/core.o: private skip_clippy = 1
387 $(obj)/core.o: private skip_flags = -Wunreacha !! 363 $(obj)/core.o: private skip_flags = -Dunreachable_pub
388 $(obj)/core.o: private rustc_objcopy = $(forea << 
389 $(obj)/core.o: private rustc_target_flags = $(    364 $(obj)/core.o: private rustc_target_flags = $(core-cfgs)
390 $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs !! 365 $(obj)/core.o: $(RUST_LIB_SRC)/core/src/lib.rs $(obj)/target.json FORCE
391     $(wildcard $(objtree)/include/config/RUSTC !! 366         $(call if_changed_dep,rustc_library)
392         +$(call if_changed_rule,rustc_library) << 
393 ifneq ($(or $(CONFIG_X86_64),$(CONFIG_X86_32)) << 
394 $(obj)/core.o: scripts/target.json             << 
395 endif                                          << 
396                                                   367 
397 $(obj)/compiler_builtins.o: private rustc_objc    368 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
398 $(obj)/compiler_builtins.o: $(src)/compiler_bu    369 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
399         +$(call if_changed_rule,rustc_library) !! 370         $(call if_changed_dep,rustc_library)
400                                                   371 
401 $(obj)/alloc.o: private skip_clippy = 1           372 $(obj)/alloc.o: private skip_clippy = 1
402 $(obj)/alloc.o: private skip_flags = -Wunreach !! 373 $(obj)/alloc.o: private skip_flags = -Dunreachable_pub
403 $(obj)/alloc.o: private rustc_target_flags = $    374 $(obj)/alloc.o: private rustc_target_flags = $(alloc-cfgs)
404 $(obj)/alloc.o: $(RUST_LIB_SRC)/alloc/src/lib. !! 375 $(obj)/alloc.o: $(src)/alloc/lib.rs $(obj)/compiler_builtins.o FORCE
405         +$(call if_changed_rule,rustc_library) !! 376         $(call if_changed_dep,rustc_library)
406                                                   377 
407 $(obj)/build_error.o: $(src)/build_error.rs $(    378 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
408         +$(call if_changed_rule,rustc_library) !! 379         $(call if_changed_dep,rustc_library)
409                                                   380 
410 $(obj)/bindings.o: $(src)/bindings/lib.rs \       381 $(obj)/bindings.o: $(src)/bindings/lib.rs \
411     $(obj)/compiler_builtins.o \                  382     $(obj)/compiler_builtins.o \
412     $(obj)/bindings/bindings_generated.rs \       383     $(obj)/bindings/bindings_generated.rs \
413     $(obj)/bindings/bindings_helpers_generated    384     $(obj)/bindings/bindings_helpers_generated.rs FORCE
414         +$(call if_changed_rule,rustc_library) !! 385         $(call if_changed_dep,rustc_library)
415                                                << 
416 $(obj)/uapi.o: $(src)/uapi/lib.rs \            << 
417     $(obj)/compiler_builtins.o \               << 
418     $(obj)/uapi/uapi_generated.rs FORCE        << 
419         +$(call if_changed_rule,rustc_library) << 
420                                                   386 
421 $(obj)/kernel.o: private rustc_target_flags =     387 $(obj)/kernel.o: private rustc_target_flags = --extern alloc \
422     --extern build_error --extern macros --ext !! 388     --extern build_error --extern macros --extern bindings
423 $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/a    389 $(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/alloc.o $(obj)/build_error.o \
424     $(obj)/libmacros.so $(obj)/bindings.o $(ob !! 390     $(obj)/libmacros.so $(obj)/bindings.o FORCE
425         +$(call if_changed_rule,rustc_library) !! 391         $(call if_changed_dep,rustc_library)
426                                                   392 
427 endif # CONFIG_RUST                               393 endif # CONFIG_RUST
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php