Skip to content

Commit 34d7f7e

Browse files
authored
Auto merge of #34606 - mathstuf:llvm-with-ninja, r=alexcrichton
llvm, rt: build using the Ninja generator if available The Ninja generator generally builds much faster than make. It may also be used on Windows to have a vast speed improvement over the Visual Studio generators. Currently hidden behind an `--enable-ninja` flag because it does not obey the top-level `-j` or `-l` flags given to `make`.
2 parents 103e5c9 + b9a3590 commit 34d7f7e

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

configure

+16-1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ opt rustbuild 0 "use the rust and cargo based build system"
612612
opt orbit 0 "get MIR where it belongs - everywhere; most importantly, in orbit"
613613
opt codegen-tests 1 "run the src/test/codegen tests"
614614
opt option-checking 1 "complain about unrecognized options in this configure script"
615+
opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
615616

616617
# Optimization and debugging options. These may be overridden by the release channel, etc.
617618
opt_nosave optimize 1 "build optimized rust code"
@@ -785,6 +786,17 @@ probe CFG_BISON bison
785786
probe CFG_GDB gdb
786787
probe CFG_LLDB lldb
787788

789+
if [ -n "$CFG_ENABLE_NINJA" ]
790+
then
791+
probe CFG_NINJA ninja
792+
if [ -z "$CFG_NINJA" ]
793+
then
794+
# On Debian and Fedora, the `ninja` binary is an IRC bot, so the build tool was
795+
# renamed. Handle this case.
796+
probe CFG_NINJA ninja-build
797+
fi
798+
fi
799+
788800
# For building LLVM
789801
probe_need CFG_CMAKE cmake
790802

@@ -1534,7 +1546,10 @@ do
15341546
fi
15351547

15361548
# We need the generator later on for compiler-rt even if LLVM's not built
1537-
if [ ${is_msvc} -ne 0 ]
1549+
if [ -n "$CFG_NINJA" ]
1550+
then
1551+
generator="Ninja"
1552+
elif [ ${is_msvc} -ne 0 ]
15381553
then
15391554
case "$CFG_MSVC_ROOT" in
15401555
*14.0*)

mk/llvm.mk

+12-2
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,26 @@ $$(LLVM_CONFIG_$(1)): $$(LLVM_DONE_$(1))
4343

4444
$$(LLVM_DONE_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
4545
@$$(call E, cmake: llvm)
46-
ifeq ($$(findstring msvc,$(1)),msvc)
46+
ifneq ($$(CFG_NINJA),)
47+
$$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1))
48+
else ifeq ($$(findstring msvc,$(1)),msvc)
4749
$$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
4850
--config $$(LLVM_BUILD_CONFIG_MODE)
4951
else
5052
$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1))
5153
endif
5254
$$(Q)touch $$@
5355

54-
ifeq ($$(findstring msvc,$(1)),msvc)
56+
ifneq ($$(CFG_NINJA),)
5557
clean-llvm$(1):
58+
@$$(call E, clean: llvm)
59+
$$(Q)$$(CFG_NINJA) -C $$(CFG_LLVM_BUILD_DIR_$(1)) -t clean
60+
else ifeq ($$(findstring msvc,$(1)),msvc)
61+
clean-llvm$(1):
62+
@$$(call E, clean: llvm)
63+
$$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
64+
--config $$(LLVM_BUILD_CONFIG_MODE) \
65+
--target clean
5666
else
5767
clean-llvm$(1):
5868
@$$(call E, clean: llvm)

mk/rt.mk

+7
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,17 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD
350350
$$(COMPRT_DEFINES_$(1)) \
351351
$$(COMPRT_BUILD_CC_$(1)) \
352352
-G"$$(CFG_CMAKE_GENERATOR)"
353+
ifneq ($$(CFG_NINJA),)
354+
$$(CFG_CMAKE) --build "$$(COMPRT_BUILD_DIR_$(1))" \
355+
--target $$(COMPRT_BUILD_TARGET_$(1)) \
356+
--config $$(LLVM_BUILD_CONFIG_MODE) \
357+
-- $$(COMPRT_BUILD_ARGS_$(1))
358+
else
353359
$$(Q)$$(CFG_CMAKE) --build "$$(COMPRT_BUILD_DIR_$(1))" \
354360
--target $$(COMPRT_BUILD_TARGET_$(1)) \
355361
--config $$(LLVM_BUILD_CONFIG_MODE) \
356362
-- $$(COMPRT_BUILD_ARGS_$(1)) $$(MFLAGS)
363+
endif
357364
$$(Q)cp "$$(COMPRT_OUTPUT_$(1))" $$@
358365

359366
endif

src/bootstrap/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ impl Config {
317317
("OPTIMIZE_TESTS", self.rust_optimize_tests),
318318
("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
319319
("LOCAL_REBUILD", self.local_rebuild),
320+
("NINJA", self.ninja),
320321
}
321322

322323
match key {

0 commit comments

Comments
 (0)