1 # Make-lang.in -- Top level -*- makefile -*- fragment for GCC Rust frontend.
3 # Copyright (C) 2009-2024 Free Software Foundation, Inc.
5 # This file is part of GCC.
7 # GCC is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GCC is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GCC; see the file COPYING3. If not see
19 # <http://www.gnu.org/licenses/>.
21 # This file provides the language dependent support in the main Makefile.
25 # Use strict warnings for this front end.
26 rust-warn = $(STRICT_WARN)
27 # ..., with the exception of '-Wunused-parameter'; waiting for
28 # <https://github.com/Rust-GCC/gccrs/issues/1626> "bootstrap build failure".
29 rust-warn += -Wno-unused-parameter
31 # Installation name. Useful for cross compilers and used during install.
32 GCCRS_INSTALL_NAME := $(shell echo gccrs|sed '$(program_transform_name)')
33 GCCRS_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gccrs|sed '$(program_transform_name)')
35 # Define the names for selecting rust in LANGUAGES.
38 rust.serial = crab1$(exeext)
40 # Tell GNU make to ignore files by these names if they exist.
43 # removed GRS_CFLAGS from here
45 CFLAGS-rust/rustspec.o += $(DRIVER_DEFINES)
47 # Create the compiler driver gccrs.
48 # A compiler driver is the program that interprets command argument and can be called from the command
49 # line - e.g. gcc or g++, and not cc1, which is the actual compiler
51 # Create driver objects
57 gccrs$(exeext): $(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a $(LIBDEPS)
58 +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
59 $(GCCRS_D_OBJS) $(EXTRA_GCC_OBJS) libcommon-target.a \
60 $(EXTRA_GCC_LIBS) $(LIBS)
62 # List of host object files used by the rust language - files for translation from the parse tree
64 # The compiler proper, not driver
68 rust/rust-object-export.o \
70 rust/rust-diagnostics.o \
74 rust/rust-cfg-parser.o \
77 rust/rust-ast-formatting.o \
80 rust/rust-ast-fragment.o \
81 rust/rust-ast-dump.o \
82 rust/rust-ast-collector.o \
83 rust/rust-ast-visitor.o \
84 rust/rust-hir-dump.o \
85 rust/rust-session-manager.o \
88 rust/rust-mangle-v0.o \
89 rust/rust-mangle-legacy.o \
90 rust/rust-compile-resolve-path.o \
91 rust/rust-macro-expand.o \
92 rust/rust-cfg-strip.o \
93 rust/rust-expand-visitor.o \
94 rust/rust-ast-builder.o \
96 rust/rust-derive-clone.o \
97 rust/rust-derive-copy.o \
98 rust/rust-proc-macro.o \
99 rust/rust-macro-invoc-lexer.o \
100 rust/rust-proc-macro-invoc-lexer.o \
101 rust/rust-macro-substitute-ctx.o \
102 rust/rust-macro-builtins.o \
104 rust/rust-hir-map.o \
105 rust/rust-attributes.o \
106 rust/rust-keyword-values.o \
108 rust/rust-token-converter.o \
110 rust/rust-ast-lower.o \
111 rust/rust-ast-lower-base.o \
112 rust/rust-ast-lower-pattern.o \
113 rust/rust-ast-lower-item.o \
114 rust/rust-ast-lower-implitem.o \
115 rust/rust-ast-lower-expr.o \
116 rust/rust-ast-lower-type.o \
117 rust/rust-ast-lower-stmt.o \
119 rust/rust-name-resolution-context.o \
120 rust/rust-default-resolver.o \
121 rust/rust-toplevel-name-resolver-2.0.o \
122 rust/rust-early-name-resolver-2.0.o \
123 rust/rust-late-name-resolver-2.0.o \
124 rust/rust-early-name-resolver.o \
125 rust/rust-name-resolver.o \
126 rust/rust-ast-resolve.o \
127 rust/rust-ast-resolve-base.o \
128 rust/rust-ast-resolve-item.o \
129 rust/rust-ast-resolve-pattern.o \
130 rust/rust-ast-resolve-expr.o \
131 rust/rust-ast-resolve-type.o \
132 rust/rust-ast-resolve-path.o \
133 rust/rust-ast-resolve-stmt.o \
134 rust/rust-ast-resolve-struct-expr-field.o \
135 rust/rust-hir-type-check.o \
136 rust/rust-privacy-check.o \
137 rust/rust-privacy-ctx.o \
138 rust/rust-reachability.o \
139 rust/rust-visibility-resolver.o \
140 rust/rust-pub-restricted-visitor.o \
141 rust/rust-privacy-reporter.o \
143 rust/rust-tyty-util.o \
144 rust/rust-tyty-call.o \
145 rust/rust-tyty-subst.o \
146 rust/rust-typecheck-context.o \
147 rust/rust-tyty-bounds.o \
148 rust/rust-hir-trait-resolve.o \
149 rust/rust-hir-trait-reference.o \
150 rust/rust-hir-type-check-item.o \
151 rust/rust-hir-type-check-type.o \
152 rust/rust-hir-type-check-struct.o \
153 rust/rust-hir-type-check-pattern.o \
154 rust/rust-hir-type-check-expr.o \
155 rust/rust-hir-type-check-stmt.o \
156 rust/rust-hir-type-check-enumitem.o \
157 rust/rust-hir-type-check-implitem.o \
158 rust/rust-borrow-checker.o \
159 rust/rust-bir-builder-expr-stmt.o \
160 rust/rust-bir-dump.o \
161 rust/rust-hir-dot-operator.o \
162 rust/rust-hir-path-probe.o \
163 rust/rust-type-util.o \
164 rust/rust-coercion.o \
167 rust/rust-hir-type-check-base.o \
168 rust/rust-autoderef.o \
169 rust/rust-substitution-mapper.o \
170 rust/rust-const-checker.o \
171 rust/rust-lint-marklive.o \
172 rust/rust-lint-unused-var.o \
173 rust/rust-readonly-check.o \
174 rust/rust-hir-type-check-path.o \
175 rust/rust-unsafe-checker.o \
176 rust/rust-compile-intrinsic.o \
177 rust/rust-compile-pattern.o \
178 rust/rust-compile-fnparam.o \
179 rust/rust-compile-proc-macro.o \
181 rust/rust-compile-item.o \
182 rust/rust-compile-implitem.o \
183 rust/rust-compile-stmt.o \
184 rust/rust-compile-expr.o \
185 rust/rust-compile-type.o \
186 rust/rust-compile-block.o \
187 rust/rust-compile-struct-field-expr.o \
188 rust/rust-constexpr.o \
189 rust/rust-compile-base.o \
191 rust/rust-compile-context.o \
192 rust/rust-export-metadata.o \
193 rust/rust-imports.o \
194 rust/rust-import-archive.o \
195 rust/rust-extern-crate.o \
196 rust/rust-builtins.o \
197 rust/rust-feature.o \
198 rust/rust-feature-gate.o \
199 rust/rust-ast-validation.o \
200 rust/rust-dir-owner.o \
201 rust/rust-unicode.o \
202 rust/rust-punycode.o \
204 # removed object files from here
206 # All language-specific object files for Rust.
207 RUST_ALL_OBJS = $(GRS_OBJS) $(RUST_TARGET_OBJS)
209 rust_OBJS = $(RUST_ALL_OBJS) rust/rustspec.o
211 LIBPROC_MACRO_INTERNAL = ../libgrust/libproc_macro_internal/libproc_macro_internal.a
214 RUST_LIBDEPS = $(LIBDEPS) $(LIBPROC_MACRO_INTERNAL)
216 # The compiler itself is called crab1
217 crab1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(RUST_LIBDEPS) $(rust.prev)
218 @$(call LINK_PROGRESS,$(INDEX.rust),start)
219 +$(LLINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
220 $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBS) $(LIBPROC_MACRO_INTERNAL) $(BACKENDLIBS)
221 @$(call LINK_PROGRESS,$(INDEX.rust),end)
225 lang_checks += check-rust
226 lang_checks_parallelized += check-rust
227 check_rust_parallelize = 10
229 # Copies its dependencies into the source directory. This generally should be used for generated files
230 # such as Bison output files which are not version-controlled, but should be included in any release
231 # tarballs. This target will be executed during a bootstrap if ‘--enable-generated-files-in-srcdir’
232 # was specified as a configure option.
235 rust.all.cross: gccrs$(exeext)
237 # idk what this does but someone used it
238 rust.start.encap: gccrs$(exeext)
241 # Build generated man pages for the front end from Texinfo manuals (see Man Page Generation), in the
242 # build directory. This target is only called if the necessary tools are available, but should ignore
243 # errors so as not to stop the build if errors occur; man pages are optional and the tools involved
244 # may be installed in a broken way.
247 # Copies its dependencies into the source directory. These targets will be executed during a bootstrap
248 # if ‘--enable-generated-files-in-srcdir’ was specified as a configure option.
254 # cd $(srcdir)/rust; rm -f *.o y.tab.h y.tab.c lex.yy.c
256 rust.clean: rust.mostlyclean
258 # Builds an etags TAGS file in the language subdirectory in the source tree.
259 # TODO: add more directories if I add more
262 etags -o TAGS.sub *.y *.l *.cc *.h ast/*.h ast/*.cc lex/*.h lex/*.cc parse/*.h parse/*.cc; \
263 etags --include TAGS.sub --include ../TAGS.sub
265 # Build documentation hooks.
267 # Build info documentation for the front end, in the build directory. This target is only called by
268 # ‘make bootstrap’ if a suitable version of makeinfo is available, so does not need to check for this,
269 # and should fail if an error occurs.
274 # Build DVI documentation for the front end, in the build directory. This should be done using
275 # $(TEXI2DVI), with appropriate -I arguments pointing to directories of included files.
278 # Build PDF documentation for the front end, in the build directory. This should be done using
279 # $(TEXI2PDF), with appropriate -I arguments pointing to directories of included files.
286 # Build HTML documentation for the front end, in the build directory.
291 # Install everything that is part of the front end, apart from the compiler executables listed in
292 # compilers in config-lang.in.
293 rust.install-common: installdirs
294 # -rm -f $(DESTDIR)$(bindir)/$(GCCRS_INSTALL_NAME)$(exeext)
295 # -rm -f $(DESTDIR)$(bindir)/$(GCCRS_TARGET_INSTALL_NAME)$(exeext)
296 # $(INSTALL_PROGRAM) gccrs$(exeext) $(DESTDIR)$(bindir)/$(GCCRS_INSTALL_NAME)$(exeext)
297 # if test -f $(DESTDIR)$(bindir)$(GCCRS_TARGET_INSTALL_NAME)$(exeext); then \
300 # cd $(DESTDIR)$(bindir) && \
301 # $(LN) $(GCCRS_INSTALL_NAME)$(exeext) $(GCCRS_TARGET_INSTALL_NAME)$(exeext); \
303 -rm -f $(DESTDIR)$(bindir)/$(GCCRS_INSTALL_NAME)$(exeext)
304 $(INSTALL_PROGRAM) gccrs$(exeext) $(DESTDIR)$(bindir)/$(GCCRS_INSTALL_NAME)$(exeext)
305 rm -f $(DESTDIR)$(bindir)/$(GCCRS_TARGET_INSTALL_NAME)$(exeext); \
306 ( cd $(DESTDIR)$(bindir) && \
307 $(LN) $(GCCRS_INSTALL_NAME)$(exeext) $(GCCRS_TARGET_INSTALL_NAME)$(exeext) ); \
309 # Install headers needed for plugins.
312 # Uninstall files installed by installing the compiler. This is currently documented not to be
313 # supported, so the hook need not do anything.
315 # -rm -rf $(DESTDIR)/$(bindir)/$(GCCRS_INSTALL_NAME)$(exeext)
316 -rm -f gccrs$(exeext) grs1$(exeext)
317 -rm -f $(RUST_ALL_OBJS)
318 # ^those two are a maybe
320 # Enable selftests for the rust frontend
321 selftest-rust: s-selftest-rust
323 RUST_SELFTEST_FLAGS = -xrust -frust-incomplete-and-experimental-compiler-do-not-use $(SELFTEST_FLAGS)
324 RUST_SELFTEST_DEPS = crab1$(exeext) $(SELFTEST_DEPS)
326 # Run the rust selftests
327 s-selftest-rust: $(RUST_SELFTEST_DEPS)
328 $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS)
331 # Convenience methods for running rust selftests under gdb:
332 .PHONY: selftest-rust-gdb
333 selftest-rust-gdb: $(RUST_SELFTEST_DEPS)
334 $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS) \
337 # Convenience methods for running rust selftests under valgrind:
338 .PHONY: selftest-rust-valgrind
339 selftest-rust-valgrind: $(RUST_SELFTEST_DEPS)
340 $(GCC_FOR_TARGET) $(RUST_SELFTEST_FLAGS) \
341 -wrapper valgrind,--leak-check=full
343 # Install info documentation for the front end, if it is present in the source directory. This target
344 # should have dependencies on info files that should be installed.
351 # Install man pages for the front end. This target should ignore errors.
355 # The toplevel makefile has already created stage?/rust at this point.
356 # Used for handling bootstrap
358 rust.stage1: stage1-start
359 -mv rust/*$(objext) stage1/rust
360 rust.stage2: stage2-start
361 -mv rust/*$(objext) stage2/rust
362 rust.stage3: stage3-start
363 -mv rust/*$(objext) stage3/rust
364 rust.stage4: stage4-start
365 -mv rust/*$(objext) stage4/rust
366 rust.stageprofile: stageprofile-start
367 -mv rust/*$(objext) stageprofile/rust
368 rust.stagefeedback: stagefeedback-start
369 -mv rust/*$(objext) stagefeedback/rust
371 CFLAGS-rust/rust-lang.o += -DDEFAULT_TARGET_VERSION=\"$(version)\" \
372 -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\"
374 # cross-folder includes - add new folders later
375 RUST_INCLUDES = -I $(srcdir)/rust \
376 -I $(srcdir)/rust/lex \
377 -I $(srcdir)/rust/parse \
378 -I $(srcdir)/rust/ast \
379 -I $(srcdir)/rust/analysis \
380 -I $(srcdir)/rust/backend \
381 -I $(srcdir)/rust/expand \
382 -I $(srcdir)/rust/hir/tree \
383 -I $(srcdir)/rust/hir \
384 -I $(srcdir)/rust/resolve \
385 -I $(srcdir)/rust/util \
386 -I $(srcdir)/rust/typecheck \
387 -I $(srcdir)/rust/checks/lints \
388 -I $(srcdir)/rust/checks/errors \
389 -I $(srcdir)/rust/checks/errors/privacy \
390 -I $(srcdir)/rust/checks/errors/borrowck \
391 -I $(srcdir)/rust/util \
392 -I $(srcdir)/rust/metadata \
393 -I $(srcdir)/../libgrust
395 # add files that require cross-folder includes - currently rust-lang.o, rust-lex.o
396 CFLAGS-rust/rust-lang.o += $(RUST_INCLUDES)
397 CFLAGS-rust/rust-lex.o += $(RUST_INCLUDES)
398 CFLAGS-rust/rust-parse.o += $(RUST_INCLUDES)
399 CFLAGS-rust/rust-session-manager.o += $(RUST_INCLUDES)
401 RUST_CXXFLAGS = $(CXXFLAGS)
403 # build all rust/lex files in rust folder, add cross-folder includes
404 rust/%.o: rust/lex/%.cc
405 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
408 # build all rust/parse files in rust folder, add cross-folder includes
409 rust/%.o: rust/parse/%.cc
410 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
413 # build rust/ast files in rust folder
414 rust/%.o: rust/ast/%.cc
415 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
418 # build rust/backend files in rust folder
419 rust/%.o: rust/backend/%.cc
420 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
423 # build rust/expand files in rust folder
424 rust/%.o: rust/expand/%.cc
425 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
428 # build rust/util files in rust folder
429 rust/%.o: rust/util/%.cc
430 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
433 # build rust/hir files in rust folder
434 rust/%.o: rust/hir/%.cc
435 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
438 # build rust/hir/tree files in rust folder
439 rust/%.o: rust/hir/tree/%.cc
440 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
443 # build rust/resolve files in rust folder
444 rust/%.o: rust/resolve/%.cc
445 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
448 # build rust/typecheck files in rust folder
449 rust/%.o: rust/typecheck/%.cc
450 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
453 # build rust/checks/lints files in rust folder
454 rust/%.o: rust/checks/lints/%.cc
455 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
458 # build rust/checks/errors files in rust folder
459 rust/%.o: rust/checks/errors/%.cc
460 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
463 # build privacy pass files in rust folder
464 rust/%.o: rust/checks/errors/privacy/%.cc
465 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
468 # build borrow checking pass files in rust folder
469 rust/%.o: rust/checks/errors/borrowck/%.cc
470 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<
473 # build rust/metadata files in rust folder
474 rust/%.o: rust/metadata/%.cc
475 $(COMPILE) $(RUST_CXXFLAGS) $(RUST_INCLUDES) $<