2017-08-26 15:01:48 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
# ignore-tidy-linelength
|
|
|
|
|
|
2017-10-09 08:16:18 -07:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2024-11-05 11:32:05 +01:00
|
|
|
import shlex
|
2017-08-26 15:01:48 -07:00
|
|
|
import sys
|
|
|
|
|
import os
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
rust_dir = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
rust_dir = os.path.dirname(rust_dir)
|
|
|
|
|
rust_dir = os.path.dirname(rust_dir)
|
|
|
|
|
sys.path.append(os.path.join(rust_dir, "src", "bootstrap"))
|
2024-12-04 23:02:25 +01:00
|
|
|
import bootstrap # noqa: E402
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-10-09 08:16:18 -07:00
|
|
|
class Option(object):
|
2017-08-26 15:01:48 -07:00
|
|
|
def __init__(self, name, rustbuild, desc, value):
|
|
|
|
|
self.name = name
|
|
|
|
|
self.rustbuild = rustbuild
|
|
|
|
|
self.desc = desc
|
|
|
|
|
self.value = value
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
options = []
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
def o(*args):
|
|
|
|
|
options.append(Option(*args, value=False))
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
def v(*args):
|
|
|
|
|
options.append(Option(*args, value=True))
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"debug",
|
|
|
|
|
"rust.debug",
|
|
|
|
|
"enables debugging environment; does not affect optimization of bootstrapped code",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("docs", "build.docs", "build standard library documentation")
|
|
|
|
|
o("compiler-docs", "build.compiler-docs", "build compiler documentation")
|
|
|
|
|
o("optimize-tests", "rust.optimize-tests", "build tests with optimizations")
|
2018-06-07 14:40:36 +02:00
|
|
|
o("verbose-tests", "rust.verbose-tests", "enable verbose output when running tests")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"ccache",
|
2025-02-12 20:02:21 +01:00
|
|
|
"build.ccache",
|
|
|
|
|
"invoke gcc/clang/rustc via ccache to reuse object files between builds",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"sccache",
|
|
|
|
|
None,
|
|
|
|
|
"invoke gcc/clang/rustc via sccache to reuse object files between builds",
|
2024-12-04 23:02:25 +01:00
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("local-rust", None, "use an installed rustc rather than downloading a snapshot")
|
|
|
|
|
v("local-rust-root", None, "set prefix for local rust binary")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"local-rebuild",
|
|
|
|
|
"build.local-rebuild",
|
|
|
|
|
"assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"llvm-static-stdcpp",
|
|
|
|
|
"llvm.static-libstdcpp",
|
|
|
|
|
"statically link to libstdc++ for LLVM",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"llvm-link-shared",
|
|
|
|
|
"llvm.link-shared",
|
|
|
|
|
"prefer shared linking to LLVM (llvm-config --link-shared)",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("rpath", "rust.rpath", "build rpaths into rustc itself")
|
2023-01-05 09:45:44 +01:00
|
|
|
o("codegen-tests", "rust.codegen-tests", "run the tests/codegen tests")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"ninja",
|
|
|
|
|
"llvm.ninja",
|
|
|
|
|
"build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("locked-deps", "build.locked-deps", "force Cargo.lock to be up to date")
|
|
|
|
|
o("vendor", "build.vendor", "enable usage of vendored Rust crates")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"sanitizers",
|
|
|
|
|
"build.sanitizers",
|
|
|
|
|
"build the sanitizer runtimes (asan, dfsan, lsan, msan, tsan, hwasan)",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"dist-src",
|
|
|
|
|
"rust.dist-src",
|
|
|
|
|
"when building tarballs enables building a source tarball",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"cargo-native-static",
|
|
|
|
|
"build.cargo-native-static",
|
|
|
|
|
"static native libraries in cargo",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("profiler", "build.profiler", "build the profiler runtime")
|
rust: Import LLD for linking wasm objects
This commit imports the LLD project from LLVM to serve as the default linker for
the `wasm32-unknown-unknown` target. The `binaryen` submoule is consequently
removed along with "binaryen linker" support in rustc.
Moving to LLD brings with it a number of benefits for wasm code:
* LLD is itself an actual linker, so there's no need to compile all wasm code
with LTO any more. As a result builds should be *much* speedier as LTO is no
longer forcibly enabled for all builds of the wasm target.
* LLD is quickly becoming an "official solution" for linking wasm code together.
This, I believe at least, is intended to be the main supported linker for
native code and wasm moving forward. Picking up support early on should help
ensure that we can help LLD identify bugs and otherwise prove that it works
great for all our use cases!
* Improvements to the wasm toolchain are currently primarily focused around LLVM
and LLD (from what I can tell at least), so it's in general much better to be
on this bandwagon for bugfixes and new features.
* Historical "hacks" like `wasm-gc` will soon no longer be necessary, LLD
will [natively implement][gc] `--gc-sections` (better than `wasm-gc`!) which
means a postprocessor is no longer needed to show off Rust's "small wasm
binary size".
LLD is added in a pretty standard way to rustc right now. A new rustbuild target
was defined for building LLD, and this is executed when a compiler's sysroot is
being assembled. LLD is compiled against the LLVM that we've got in tree, which
means we're currently on the `release_60` branch, but this may get upgraded in
the near future!
LLD is placed into rustc's sysroot in a `bin` directory. This is similar to
where `gcc.exe` can be found on Windows. This directory is automatically added
to `PATH` whenever rustc executes the linker, allowing us to define a `WasmLd`
linker which implements the interface that `wasm-ld`, LLD's frontend, expects.
Like Emscripten the LLD target is currently only enabled for Tier 1 platforms,
notably OSX/Windows/Linux, and will need to be installed manually for compiling
to wasm on other platforms. LLD is by default turned off in rustbuild, and
requires a `config.toml` option to be enabled to turn it on.
Finally the unstable `#![wasm_import_memory]` attribute was also removed as LLD
has a native option for controlling this.
[gc]: https://reviews.llvm.org/D42511
2017-08-26 18:30:12 -07:00
|
|
|
o("full-tools", None, "enable all tools")
|
2018-10-15 17:27:07 -07:00
|
|
|
o("lld", "rust.lld", "build lld")
|
2024-02-06 20:09:55 +01:00
|
|
|
o("llvm-bitcode-linker", "rust.llvm-bitcode-linker", "build llvm bitcode linker")
|
2021-07-20 02:38:39 +02:00
|
|
|
o("clang", "llvm.clang", "build clang")
|
2019-12-13 14:00:47 -08:00
|
|
|
o("use-libcxx", "llvm.use-libcxx", "build LLVM with libc++")
|
2020-01-28 14:29:44 +00:00
|
|
|
o("control-flow-guard", "rust.control-flow-guard", "Enable Control Flow Guard")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"patch-binaries-for-nix",
|
|
|
|
|
"build.patch-binaries-for-nix",
|
|
|
|
|
"whether patch binaries for usage with Nix toolchains",
|
|
|
|
|
)
|
2023-10-29 01:43:18 +02:00
|
|
|
o("new-symbol-mangling", "rust.new-symbol-mangling", "use symbol-mangling-version v0")
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2020-02-17 11:01:52 -08:00
|
|
|
v("llvm-cflags", "llvm.cflags", "build LLVM with these extra compiler flags")
|
|
|
|
|
v("llvm-cxxflags", "llvm.cxxflags", "build LLVM with these extra compiler flags")
|
|
|
|
|
v("llvm-ldflags", "llvm.ldflags", "build LLVM with these extra linker flags")
|
2018-11-13 16:25:51 -08:00
|
|
|
|
2020-10-08 15:05:31 +02:00
|
|
|
v("llvm-libunwind", "rust.llvm-libunwind", "use LLVM libunwind")
|
2019-03-10 19:27:59 -07:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
# Optimization and debugging options. These may be overridden by the release
|
|
|
|
|
# channel, etc.
|
|
|
|
|
o("optimize-llvm", "llvm.optimize", "build optimized LLVM")
|
|
|
|
|
o("llvm-assertions", "llvm.assertions", "build LLVM with assertions")
|
2024-09-04 15:25:43 -04:00
|
|
|
o("llvm-enzyme", "llvm.enzyme", "build LLVM with enzyme")
|
2024-10-12 00:16:39 +02:00
|
|
|
o("llvm-offload", "llvm.offload", "build LLVM with gpu offload support")
|
2021-07-20 02:38:39 +02:00
|
|
|
o("llvm-plugins", "llvm.plugins", "build LLVM with plugin interface")
|
2017-08-26 15:01:48 -07:00
|
|
|
o("debug-assertions", "rust.debug-assertions", "build with debugging assertions")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"debug-assertions-std",
|
|
|
|
|
"rust.debug-assertions-std",
|
|
|
|
|
"build the standard library with debugging assertions",
|
|
|
|
|
)
|
2021-08-05 05:28:40 +00:00
|
|
|
o("overflow-checks", "rust.overflow-checks", "build with overflow checks")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"overflow-checks-std",
|
|
|
|
|
"rust.overflow-checks-std",
|
|
|
|
|
"build the standard library with overflow checks",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"llvm-release-debuginfo",
|
|
|
|
|
"llvm.release-debuginfo",
|
|
|
|
|
"build LLVM with debugger metadata",
|
|
|
|
|
)
|
2019-07-23 12:04:31 -07:00
|
|
|
v("debuginfo-level", "rust.debuginfo-level", "debuginfo level for Rust code")
|
2024-12-04 23:02:25 +01:00
|
|
|
v(
|
|
|
|
|
"debuginfo-level-rustc",
|
|
|
|
|
"rust.debuginfo-level-rustc",
|
|
|
|
|
"debuginfo level for the compiler",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"debuginfo-level-std",
|
|
|
|
|
"rust.debuginfo-level-std",
|
|
|
|
|
"debuginfo level for the standard library",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"debuginfo-level-tools",
|
|
|
|
|
"rust.debuginfo-level-tools",
|
|
|
|
|
"debuginfo level for the tools",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"debuginfo-level-tests",
|
|
|
|
|
"rust.debuginfo-level-tests",
|
|
|
|
|
"debuginfo level for the test suites run with compiletest",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"save-toolstates",
|
|
|
|
|
"rust.save-toolstates",
|
|
|
|
|
"save build and test status of external tools into this file",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
|
|
|
|
|
v("prefix", "install.prefix", "set installation prefix")
|
|
|
|
|
v("localstatedir", "install.localstatedir", "local state directory")
|
|
|
|
|
v("datadir", "install.datadir", "install data")
|
|
|
|
|
v("sysconfdir", "install.sysconfdir", "install system configuration files")
|
|
|
|
|
v("infodir", "install.infodir", "install additional info")
|
|
|
|
|
v("libdir", "install.libdir", "install libraries")
|
|
|
|
|
v("mandir", "install.mandir", "install man pages in PATH")
|
|
|
|
|
v("docdir", "install.docdir", "install documentation in PATH")
|
|
|
|
|
v("bindir", "install.bindir", "install binaries")
|
|
|
|
|
|
|
|
|
|
v("llvm-root", None, "set LLVM root")
|
2018-09-25 09:13:02 -06:00
|
|
|
v("llvm-config", None, "set path to llvm-config")
|
|
|
|
|
v("llvm-filecheck", None, "set path to LLVM's FileCheck utility")
|
2017-08-26 15:01:48 -07:00
|
|
|
v("python", "build.python", "set path to python")
|
2022-10-12 17:02:31 -07:00
|
|
|
v("android-ndk", "build.android-ndk", "set path to Android NDK")
|
2024-12-04 23:02:25 +01:00
|
|
|
v(
|
|
|
|
|
"musl-root",
|
|
|
|
|
"target.x86_64-unknown-linux-musl.musl-root",
|
|
|
|
|
"MUSL root installation directory (deprecated)",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-x86_64",
|
|
|
|
|
"target.x86_64-unknown-linux-musl.musl-root",
|
|
|
|
|
"x86_64-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-i586",
|
|
|
|
|
"target.i586-unknown-linux-musl.musl-root",
|
|
|
|
|
"i586-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-i686",
|
|
|
|
|
"target.i686-unknown-linux-musl.musl-root",
|
|
|
|
|
"i686-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-arm",
|
|
|
|
|
"target.arm-unknown-linux-musleabi.musl-root",
|
|
|
|
|
"arm-unknown-linux-musleabi install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-armhf",
|
|
|
|
|
"target.arm-unknown-linux-musleabihf.musl-root",
|
|
|
|
|
"arm-unknown-linux-musleabihf install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-armv5te",
|
|
|
|
|
"target.armv5te-unknown-linux-musleabi.musl-root",
|
|
|
|
|
"armv5te-unknown-linux-musleabi install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-armv7",
|
|
|
|
|
"target.armv7-unknown-linux-musleabi.musl-root",
|
|
|
|
|
"armv7-unknown-linux-musleabi install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-armv7hf",
|
|
|
|
|
"target.armv7-unknown-linux-musleabihf.musl-root",
|
|
|
|
|
"armv7-unknown-linux-musleabihf install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-aarch64",
|
|
|
|
|
"target.aarch64-unknown-linux-musl.musl-root",
|
|
|
|
|
"aarch64-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-mips",
|
|
|
|
|
"target.mips-unknown-linux-musl.musl-root",
|
|
|
|
|
"mips-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-mipsel",
|
|
|
|
|
"target.mipsel-unknown-linux-musl.musl-root",
|
|
|
|
|
"mipsel-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-mips64",
|
|
|
|
|
"target.mips64-unknown-linux-muslabi64.musl-root",
|
|
|
|
|
"mips64-unknown-linux-muslabi64 install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-mips64el",
|
|
|
|
|
"target.mips64el-unknown-linux-muslabi64.musl-root",
|
|
|
|
|
"mips64el-unknown-linux-muslabi64 install directory",
|
|
|
|
|
)
|
2024-11-18 14:26:40 +01:00
|
|
|
v(
|
|
|
|
|
"musl-root-powerpc64le",
|
|
|
|
|
"target.powerpc64le-unknown-linux-musl.musl-root",
|
|
|
|
|
"powerpc64le-unknown-linux-musl install directory",
|
|
|
|
|
)
|
2024-12-04 23:02:25 +01:00
|
|
|
v(
|
|
|
|
|
"musl-root-riscv32gc",
|
|
|
|
|
"target.riscv32gc-unknown-linux-musl.musl-root",
|
|
|
|
|
"riscv32gc-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-riscv64gc",
|
|
|
|
|
"target.riscv64gc-unknown-linux-musl.musl-root",
|
|
|
|
|
"riscv64gc-unknown-linux-musl install directory",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"musl-root-loongarch64",
|
|
|
|
|
"target.loongarch64-unknown-linux-musl.musl-root",
|
|
|
|
|
"loongarch64-unknown-linux-musl install directory",
|
|
|
|
|
)
|
2024-07-02 18:19:42 -04:00
|
|
|
v(
|
|
|
|
|
"musl-root-wali-wasm32",
|
|
|
|
|
"target.wasm32-wali-linux-musl.musl-root",
|
|
|
|
|
"wasm32-wali-linux-musl install directory",
|
|
|
|
|
)
|
2024-12-04 23:02:25 +01:00
|
|
|
v(
|
|
|
|
|
"qemu-armhf-rootfs",
|
|
|
|
|
"target.arm-unknown-linux-gnueabihf.qemu-rootfs",
|
|
|
|
|
"rootfs in qemu testing, you probably don't want to use this",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"qemu-aarch64-rootfs",
|
|
|
|
|
"target.aarch64-unknown-linux-gnu.qemu-rootfs",
|
|
|
|
|
"rootfs in qemu testing, you probably don't want to use this",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"qemu-riscv64-rootfs",
|
|
|
|
|
"target.riscv64gc-unknown-linux-gnu.qemu-rootfs",
|
|
|
|
|
"rootfs in qemu testing, you probably don't want to use this",
|
|
|
|
|
)
|
|
|
|
|
v(
|
|
|
|
|
"experimental-targets",
|
|
|
|
|
"llvm.experimental-targets",
|
|
|
|
|
"experimental LLVM targets to build",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
v("release-channel", "rust.channel", "the name of the release channel to build")
|
2024-12-04 23:02:25 +01:00
|
|
|
v(
|
|
|
|
|
"release-description",
|
2025-02-27 22:00:09 +03:00
|
|
|
"build.description",
|
2024-12-04 23:02:25 +01:00
|
|
|
"optional descriptive string for version output",
|
|
|
|
|
)
|
2023-04-20 00:48:36 +08:00
|
|
|
v("dist-compression-formats", None, "List of compression formats to use")
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2017-10-08 11:41:12 +03:00
|
|
|
# Used on systems where "cc" is unavailable
|
2017-08-26 15:01:48 -07:00
|
|
|
v("default-linker", "rust.default-linker", "the default linker")
|
|
|
|
|
|
|
|
|
|
# Many of these are saved below during the "writing configuration" step
|
|
|
|
|
# (others are conditionally saved).
|
|
|
|
|
o("manage-submodules", "build.submodules", "let the build manage the git submodules")
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"full-bootstrap",
|
|
|
|
|
"build.full-bootstrap",
|
|
|
|
|
"build three compilers instead of two (not recommended except for testing reproducible builds)",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
o("extended", "build.extended", "build an extended rust tool set")
|
|
|
|
|
|
2024-04-11 14:57:10 +03:00
|
|
|
v("bootstrap-cache-path", None, "use provided path for the bootstrap cache")
|
2018-04-08 14:59:15 +10:00
|
|
|
v("tools", None, "List of extended tools will be installed")
|
2021-07-19 16:48:12 +02:00
|
|
|
v("codegen-backends", None, "List of codegen backends to build")
|
2017-08-26 15:01:48 -07:00
|
|
|
v("build", "build.build", "GNUs ./configure syntax LLVM build triple")
|
2023-04-20 00:48:36 +08:00
|
|
|
v("host", None, "List of GNUs ./configure syntax LLVM host triples")
|
|
|
|
|
v("target", None, "List of GNUs ./configure syntax LLVM target triples")
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-05-31 11:36:58 -05:00
|
|
|
# Options specific to this configure script
|
2024-12-04 23:02:25 +01:00
|
|
|
o(
|
|
|
|
|
"option-checking",
|
|
|
|
|
None,
|
|
|
|
|
"complain about unrecognized options in this configure script",
|
|
|
|
|
)
|
|
|
|
|
o(
|
|
|
|
|
"verbose-configure",
|
|
|
|
|
None,
|
|
|
|
|
"don't truncate options when printing them in this configure script",
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
v("set", None, "set arbitrary key/value pairs in TOML configuration")
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
def p(msg):
|
|
|
|
|
print("configure: " + msg)
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
def err(msg):
|
2023-07-01 22:02:55 -04:00
|
|
|
print("\nconfigure: ERROR: " + msg + "\n")
|
2017-08-26 15:01:48 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2023-03-29 00:00:15 +08:00
|
|
|
def is_value_list(key):
|
|
|
|
|
for option in options:
|
2024-12-04 23:02:25 +01:00
|
|
|
if option.name == key and option.desc.startswith("List of"):
|
2023-03-29 00:00:15 +08:00
|
|
|
return True
|
|
|
|
|
return False
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
|
|
|
|
if "--help" in sys.argv or "-h" in sys.argv:
|
|
|
|
|
print("Usage: ./configure [options]")
|
|
|
|
|
print("")
|
|
|
|
|
print("Options")
|
2017-08-26 15:01:48 -07:00
|
|
|
for option in options:
|
2024-12-04 23:02:25 +01:00
|
|
|
if "android" in option.name:
|
2017-08-26 15:01:48 -07:00
|
|
|
# no one needs to know about these obscure options
|
|
|
|
|
continue
|
|
|
|
|
if option.value:
|
2024-12-04 23:02:25 +01:00
|
|
|
print("\t{:30} {}".format("--{}=VAL".format(option.name), option.desc))
|
2017-08-26 15:01:48 -07:00
|
|
|
else:
|
2024-12-04 23:02:25 +01:00
|
|
|
print("\t--enable-{:25} OR --disable-{}".format(option.name, option.name))
|
|
|
|
|
print("\t\t" + option.desc)
|
|
|
|
|
print("")
|
|
|
|
|
print("This configure script is a thin configuration shim over the true")
|
2025-02-15 19:32:23 +05:30
|
|
|
print("configuration system, `bootstrap.toml`. You can explore the comments")
|
|
|
|
|
print("in `bootstrap.example.toml` next to this configure script to see")
|
2024-12-04 23:02:25 +01:00
|
|
|
print("more information about what each option is. Additionally you can")
|
|
|
|
|
print("pass `--set` as an argument to set arbitrary key/value pairs")
|
|
|
|
|
print("in the TOML configuration if desired")
|
|
|
|
|
print("")
|
|
|
|
|
print("Also note that all options which take `--enable` can similarly")
|
|
|
|
|
print("be passed with `--disable-foo` to forcibly disable the option")
|
2017-08-26 15:01:48 -07:00
|
|
|
sys.exit(0)
|
|
|
|
|
|
2023-05-31 11:36:58 -05:00
|
|
|
VERBOSE = False
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
# Parse all command line arguments into one of these three lists, handling
|
|
|
|
|
# boolean and value-based options separately
|
2023-03-17 10:24:40 -05:00
|
|
|
def parse_args(args):
|
|
|
|
|
unknown_args = []
|
|
|
|
|
need_value_args = []
|
|
|
|
|
known_args = {}
|
|
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
while i < len(args):
|
|
|
|
|
arg = args[i]
|
|
|
|
|
i += 1
|
2024-12-04 23:02:25 +01:00
|
|
|
if not arg.startswith("--"):
|
2023-03-17 10:24:40 -05:00
|
|
|
unknown_args.append(arg)
|
|
|
|
|
continue
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
found = False
|
|
|
|
|
for option in options:
|
|
|
|
|
value = None
|
|
|
|
|
if option.value:
|
2024-12-04 23:02:25 +01:00
|
|
|
keyval = arg[2:].split("=", 1)
|
2023-03-17 10:24:40 -05:00
|
|
|
key = keyval[0]
|
|
|
|
|
if option.name != key:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if len(keyval) > 1:
|
|
|
|
|
value = keyval[1]
|
|
|
|
|
elif i < len(args):
|
|
|
|
|
value = args[i]
|
|
|
|
|
i += 1
|
|
|
|
|
else:
|
|
|
|
|
need_value_args.append(arg)
|
|
|
|
|
continue
|
2017-08-26 15:01:48 -07:00
|
|
|
else:
|
2024-12-04 23:02:25 +01:00
|
|
|
if arg[2:] == "enable-" + option.name:
|
2023-03-17 10:24:40 -05:00
|
|
|
value = True
|
2024-12-04 23:02:25 +01:00
|
|
|
elif arg[2:] == "disable-" + option.name:
|
2023-03-17 10:24:40 -05:00
|
|
|
value = False
|
|
|
|
|
else:
|
|
|
|
|
continue
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
found = True
|
|
|
|
|
if option.name not in known_args:
|
|
|
|
|
known_args[option.name] = []
|
|
|
|
|
known_args[option.name].append((option, value))
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if not found:
|
|
|
|
|
unknown_args.append(arg)
|
2023-03-17 10:39:40 -05:00
|
|
|
|
2023-11-08 13:31:15 +03:00
|
|
|
# NOTE: here and a few other places, we use [-1] to apply the *last* value
|
2023-03-17 10:24:40 -05:00
|
|
|
# passed. But if option-checking is enabled, then the known_args loop will
|
|
|
|
|
# also assert that options are only passed once.
|
2024-12-04 23:02:25 +01:00
|
|
|
option_checking = (
|
|
|
|
|
"option-checking" not in known_args or known_args["option-checking"][-1][1]
|
|
|
|
|
)
|
2023-03-17 10:24:40 -05:00
|
|
|
if option_checking:
|
|
|
|
|
if len(unknown_args) > 0:
|
|
|
|
|
err("Option '" + unknown_args[0] + "' is not recognized")
|
|
|
|
|
if len(need_value_args) > 0:
|
|
|
|
|
err("Option '{0}' needs a value ({0}=val)".format(need_value_args[0]))
|
|
|
|
|
|
2023-05-31 11:36:58 -05:00
|
|
|
global VERBOSE
|
2024-12-04 23:02:25 +01:00
|
|
|
VERBOSE = "verbose-configure" in known_args
|
2023-05-31 11:36:58 -05:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
config = {}
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
set("build.configure-args", args, config)
|
2023-03-17 10:24:40 -05:00
|
|
|
apply_args(known_args, option_checking, config)
|
|
|
|
|
return parse_example_config(known_args, config)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def build(known_args):
|
2024-12-04 23:02:25 +01:00
|
|
|
if "build" in known_args:
|
|
|
|
|
return known_args["build"][-1][1]
|
2020-10-28 23:09:41 -04:00
|
|
|
return bootstrap.default_build_triple(verbose=False)
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
def set(key, value, config):
|
2022-03-10 12:39:29 -08:00
|
|
|
if isinstance(value, list):
|
2024-11-05 11:32:05 +01:00
|
|
|
# Remove empty values, which value.split(',') tends to generate and
|
|
|
|
|
# replace single quotes for double quotes to ensure correct parsing.
|
2024-12-04 23:02:25 +01:00
|
|
|
value = [v.replace("'", '"') for v in value if v]
|
2022-03-10 12:39:29 -08:00
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
s = "{:20} := {}".format(key, value)
|
2023-05-31 11:36:58 -05:00
|
|
|
if len(s) < 70 or VERBOSE:
|
2017-10-08 20:08:11 -04:00
|
|
|
p(s)
|
|
|
|
|
else:
|
|
|
|
|
p(s[:70] + " ...")
|
|
|
|
|
|
|
|
|
|
arr = config
|
2024-11-05 11:32:05 +01:00
|
|
|
|
|
|
|
|
# Split `key` on periods using shell semantics.
|
|
|
|
|
lexer = shlex.shlex(key, posix=True)
|
|
|
|
|
lexer.whitespace = "."
|
|
|
|
|
lexer.wordchars += "-"
|
|
|
|
|
parts = list(lexer)
|
|
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
for i, part in enumerate(parts):
|
|
|
|
|
if i == len(parts) - 1:
|
2023-04-27 00:32:01 +08:00
|
|
|
if is_value_list(part) and isinstance(value, str):
|
2024-12-04 23:02:25 +01:00
|
|
|
value = value.split(",")
|
2017-10-08 20:08:11 -04:00
|
|
|
arr[part] = value
|
|
|
|
|
else:
|
|
|
|
|
if part not in arr:
|
|
|
|
|
arr[part] = {}
|
|
|
|
|
arr = arr[part]
|
|
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
def apply_args(known_args, option_checking, config):
|
|
|
|
|
for key in known_args:
|
|
|
|
|
# The `set` option is special and can be passed a bunch of times
|
2024-12-04 23:02:25 +01:00
|
|
|
if key == "set":
|
2023-06-10 12:06:17 -04:00
|
|
|
for _option, value in known_args[key]:
|
2024-12-04 23:02:25 +01:00
|
|
|
keyval = value.split("=", 1)
|
2023-03-17 10:24:40 -05:00
|
|
|
if len(keyval) == 1 or keyval[1] == "true":
|
|
|
|
|
value = True
|
|
|
|
|
elif keyval[1] == "false":
|
|
|
|
|
value = False
|
|
|
|
|
else:
|
|
|
|
|
value = keyval[1]
|
|
|
|
|
set(keyval[0], value, config)
|
|
|
|
|
continue
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
# Ensure each option is only passed once
|
|
|
|
|
arr = known_args[key]
|
|
|
|
|
if option_checking and len(arr) > 1:
|
|
|
|
|
err("Option '{}' provided more than once".format(key))
|
|
|
|
|
option, value = arr[-1]
|
|
|
|
|
|
|
|
|
|
# If we have a clear avenue to set our value in rustbuild, do so
|
|
|
|
|
if option.rustbuild is not None:
|
|
|
|
|
set(option.rustbuild, value, config)
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# Otherwise we're a "special" option and need some extra handling, so do
|
|
|
|
|
# that here.
|
|
|
|
|
build_triple = build(known_args)
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
if option.name == "sccache":
|
2025-02-12 20:02:21 +01:00
|
|
|
set("build.ccache", "sccache", config)
|
2024-12-04 23:02:25 +01:00
|
|
|
elif option.name == "local-rust":
|
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
|
if os.path.exists(path + "/rustc"):
|
|
|
|
|
set("build.rustc", path + "/rustc", config)
|
2023-03-17 10:24:40 -05:00
|
|
|
break
|
2024-12-04 23:02:25 +01:00
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
|
if os.path.exists(path + "/cargo"):
|
|
|
|
|
set("build.cargo", path + "/cargo", config)
|
2023-03-17 10:24:40 -05:00
|
|
|
break
|
2024-12-04 23:02:25 +01:00
|
|
|
elif option.name == "local-rust-root":
|
|
|
|
|
set("build.rustc", value + "/bin/rustc", config)
|
|
|
|
|
set("build.cargo", value + "/bin/cargo", config)
|
|
|
|
|
elif option.name == "llvm-root":
|
|
|
|
|
set(
|
|
|
|
|
"target.{}.llvm-config".format(build_triple),
|
|
|
|
|
value + "/bin/llvm-config",
|
|
|
|
|
config,
|
|
|
|
|
)
|
|
|
|
|
elif option.name == "llvm-config":
|
|
|
|
|
set("target.{}.llvm-config".format(build_triple), value, config)
|
|
|
|
|
elif option.name == "llvm-filecheck":
|
|
|
|
|
set("target.{}.llvm-filecheck".format(build_triple), value, config)
|
|
|
|
|
elif option.name == "tools":
|
|
|
|
|
set("build.tools", value.split(","), config)
|
|
|
|
|
elif option.name == "bootstrap-cache-path":
|
|
|
|
|
set("build.bootstrap-cache-path", value, config)
|
|
|
|
|
elif option.name == "codegen-backends":
|
|
|
|
|
set("rust.codegen-backends", value.split(","), config)
|
|
|
|
|
elif option.name == "host":
|
|
|
|
|
set("build.host", value.split(","), config)
|
|
|
|
|
elif option.name == "target":
|
|
|
|
|
set("build.target", value.split(","), config)
|
|
|
|
|
elif option.name == "full-tools":
|
|
|
|
|
set("rust.codegen-backends", ["llvm"], config)
|
|
|
|
|
set("rust.lld", True, config)
|
|
|
|
|
set("rust.llvm-tools", True, config)
|
|
|
|
|
set("rust.llvm-bitcode-linker", True, config)
|
|
|
|
|
set("build.extended", True, config)
|
|
|
|
|
elif option.name in ["option-checking", "verbose-configure"]:
|
2023-03-17 10:24:40 -05:00
|
|
|
# this was handled above
|
|
|
|
|
pass
|
2024-12-04 23:02:25 +01:00
|
|
|
elif option.name == "dist-compression-formats":
|
|
|
|
|
set("dist.compression-formats", value.split(","), config)
|
2023-03-17 10:24:40 -05:00
|
|
|
else:
|
|
|
|
|
raise RuntimeError("unhandled option {}".format(option.name))
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2025-02-15 19:32:23 +05:30
|
|
|
# "Parse" the `bootstrap.example.toml` file into the various sections, and we'll
|
|
|
|
|
# use this as a template of a `bootstrap.toml` to write out which preserves
|
2017-08-26 15:01:48 -07:00
|
|
|
# all the various comments and whatnot.
|
|
|
|
|
#
|
|
|
|
|
# Note that the `target` section is handled separately as we'll duplicate it
|
2018-07-03 12:24:24 -06:00
|
|
|
# per configured target, so there's a bit of special handling for that here.
|
2023-03-17 10:24:40 -05:00
|
|
|
def parse_example_config(known_args, config):
|
|
|
|
|
sections = {}
|
|
|
|
|
cur_section = None
|
|
|
|
|
sections[None] = []
|
|
|
|
|
section_order = [None]
|
|
|
|
|
targets = {}
|
|
|
|
|
top_level_keys = []
|
|
|
|
|
|
2025-02-15 19:32:23 +05:30
|
|
|
with open(rust_dir + "/bootstrap.example.toml") as example_config:
|
2023-06-25 10:01:04 -05:00
|
|
|
example_lines = example_config.read().split("\n")
|
|
|
|
|
for line in example_lines:
|
2023-06-10 12:06:17 -04:00
|
|
|
if cur_section is None:
|
2024-12-04 23:02:25 +01:00
|
|
|
if line.count("=") == 1:
|
|
|
|
|
top_level_key = line.split("=")[0]
|
|
|
|
|
top_level_key = top_level_key.strip(" #")
|
2023-03-17 10:24:40 -05:00
|
|
|
top_level_keys.append(top_level_key)
|
2024-12-04 23:02:25 +01:00
|
|
|
if line.startswith("["):
|
2023-03-17 10:24:40 -05:00
|
|
|
cur_section = line[1:-1]
|
2024-12-04 23:02:25 +01:00
|
|
|
if cur_section.startswith("target"):
|
|
|
|
|
cur_section = "target"
|
|
|
|
|
elif "." in cur_section:
|
|
|
|
|
raise RuntimeError(
|
|
|
|
|
"don't know how to deal with section: {}".format(cur_section)
|
|
|
|
|
)
|
2023-03-17 10:24:40 -05:00
|
|
|
sections[cur_section] = [line]
|
|
|
|
|
section_order.append(cur_section)
|
|
|
|
|
else:
|
|
|
|
|
sections[cur_section].append(line)
|
|
|
|
|
|
|
|
|
|
# Fill out the `targets` array by giving all configured targets a copy of the
|
|
|
|
|
# `target` section we just loaded from the example config
|
|
|
|
|
configured_targets = [build(known_args)]
|
2024-12-04 23:02:25 +01:00
|
|
|
if "build" in config:
|
|
|
|
|
if "host" in config["build"]:
|
|
|
|
|
configured_targets += config["build"]["host"]
|
|
|
|
|
if "target" in config["build"]:
|
|
|
|
|
configured_targets += config["build"]["target"]
|
|
|
|
|
if "target" in config:
|
|
|
|
|
for target in config["target"]:
|
2023-03-17 10:24:40 -05:00
|
|
|
configured_targets.append(target)
|
|
|
|
|
for target in configured_targets:
|
2024-12-04 23:02:25 +01:00
|
|
|
targets[target] = sections["target"][:]
|
2023-03-17 10:24:40 -05:00
|
|
|
# For `.` to be valid TOML, it needs to be quoted. But `bootstrap.py` doesn't use a proper TOML parser and fails to parse the target.
|
|
|
|
|
# Avoid using quotes unless it's necessary.
|
2024-12-04 23:02:25 +01:00
|
|
|
targets[target][0] = targets[target][0].replace(
|
|
|
|
|
"x86_64-unknown-linux-gnu",
|
|
|
|
|
"'{}'".format(target) if "." in target else target,
|
|
|
|
|
)
|
2023-03-17 10:24:40 -05:00
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
if "profile" not in config:
|
|
|
|
|
set("profile", "dist", config)
|
2023-03-17 10:24:40 -05:00
|
|
|
configure_file(sections, top_level_keys, targets, config)
|
|
|
|
|
return section_order, sections, targets
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2018-10-23 15:35:49 +02:00
|
|
|
def is_number(value):
|
2020-02-07 22:09:55 -05:00
|
|
|
try:
|
|
|
|
|
float(value)
|
|
|
|
|
return True
|
|
|
|
|
except ValueError:
|
|
|
|
|
return False
|
|
|
|
|
|
2018-10-23 15:35:49 +02:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
# Here we walk through the constructed configuration we have from the parsed
|
2017-10-08 19:11:34 -04:00
|
|
|
# command line arguments. We then apply each piece of configuration by
|
2017-08-26 15:01:48 -07:00
|
|
|
# basically just doing a `sed` to change the various configuration line to what
|
|
|
|
|
# we've got configure.
|
|
|
|
|
def to_toml(value):
|
|
|
|
|
if isinstance(value, bool):
|
|
|
|
|
if value:
|
|
|
|
|
return "true"
|
|
|
|
|
else:
|
|
|
|
|
return "false"
|
|
|
|
|
elif isinstance(value, list):
|
2024-12-04 23:02:25 +01:00
|
|
|
return "[" + ", ".join(map(to_toml, value)) + "]"
|
2017-08-26 15:01:48 -07:00
|
|
|
elif isinstance(value, str):
|
2018-10-23 15:35:49 +02:00
|
|
|
# Don't put quotes around numeric values
|
|
|
|
|
if is_number(value):
|
|
|
|
|
return value
|
|
|
|
|
else:
|
|
|
|
|
return "'" + value + "'"
|
2023-03-02 13:02:15 +05:30
|
|
|
elif isinstance(value, dict):
|
2024-12-04 23:02:25 +01:00
|
|
|
return (
|
|
|
|
|
"{"
|
|
|
|
|
+ ", ".join(
|
|
|
|
|
map(
|
|
|
|
|
lambda a: "{} = {}".format(to_toml(a[0]), to_toml(a[1])),
|
|
|
|
|
value.items(),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
+ "}"
|
|
|
|
|
)
|
2017-08-26 15:01:48 -07:00
|
|
|
else:
|
2024-12-04 23:02:25 +01:00
|
|
|
raise RuntimeError("no toml")
|
2017-08-26 15:01:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def configure_section(lines, config):
|
|
|
|
|
for key in config:
|
|
|
|
|
value = config[key]
|
|
|
|
|
found = False
|
|
|
|
|
for i, line in enumerate(lines):
|
2024-12-04 23:02:25 +01:00
|
|
|
if not line.startswith("#" + key + " = "):
|
2017-08-26 15:01:48 -07:00
|
|
|
continue
|
|
|
|
|
found = True
|
|
|
|
|
lines[i] = "{} = {}".format(key, to_toml(value))
|
|
|
|
|
break
|
|
|
|
|
if not found:
|
2021-02-23 13:01:39 -05:00
|
|
|
# These are used by rpm, but aren't accepted by x.py.
|
|
|
|
|
# Give a warning that they're ignored, but not a hard error.
|
|
|
|
|
if key in ["infodir", "localstatedir"]:
|
2023-11-08 13:31:15 +03:00
|
|
|
print("WARNING: {} will be ignored".format(key))
|
2021-02-23 13:01:39 -05:00
|
|
|
else:
|
|
|
|
|
raise RuntimeError("failed to find config line for {}".format(key))
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2017-10-08 20:08:11 -04:00
|
|
|
|
2023-02-19 23:51:17 -08:00
|
|
|
def configure_top_level_key(lines, top_level_key, value):
|
|
|
|
|
for i, line in enumerate(lines):
|
2024-12-04 23:02:25 +01:00
|
|
|
if line.startswith("#" + top_level_key + " = ") or line.startswith(
|
|
|
|
|
top_level_key + " = "
|
|
|
|
|
):
|
2023-04-19 08:25:00 -05:00
|
|
|
lines[i] = "{} = {}".format(top_level_key, to_toml(value))
|
2023-02-19 23:51:17 -08:00
|
|
|
return
|
|
|
|
|
|
2023-02-18 23:34:06 -08:00
|
|
|
raise RuntimeError("failed to find config line for {}".format(top_level_key))
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-02-19 23:51:17 -08:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
# Modify `sections` to reflect the parsed arguments and example configs.
|
|
|
|
|
def configure_file(sections, top_level_keys, targets, config):
|
|
|
|
|
for section_key, section_config in config.items():
|
|
|
|
|
if section_key not in sections and section_key not in top_level_keys:
|
2024-12-04 23:02:25 +01:00
|
|
|
raise RuntimeError(
|
|
|
|
|
"config key {} not in sections or top_level_keys".format(section_key)
|
|
|
|
|
)
|
2023-03-17 10:24:40 -05:00
|
|
|
if section_key in top_level_keys:
|
|
|
|
|
configure_top_level_key(sections[None], section_key, section_config)
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
elif section_key == "target":
|
2023-03-17 10:24:40 -05:00
|
|
|
for target in section_config:
|
|
|
|
|
configure_section(targets[target], section_config[target])
|
|
|
|
|
else:
|
|
|
|
|
configure_section(sections[section_key], section_config)
|
2023-02-18 23:34:06 -08:00
|
|
|
|
2017-08-26 15:01:48 -07:00
|
|
|
|
2023-03-03 17:27:29 -05:00
|
|
|
def write_uncommented(target, f):
|
|
|
|
|
block = []
|
|
|
|
|
is_comment = True
|
|
|
|
|
|
|
|
|
|
for line in target:
|
|
|
|
|
block.append(line)
|
|
|
|
|
if len(line) == 0:
|
|
|
|
|
if not is_comment:
|
2023-06-10 12:06:17 -04:00
|
|
|
for ln in block:
|
|
|
|
|
f.write(ln + "\n")
|
2023-03-03 17:27:29 -05:00
|
|
|
block = []
|
|
|
|
|
is_comment = True
|
|
|
|
|
continue
|
2024-12-04 23:02:25 +01:00
|
|
|
is_comment = is_comment and line.startswith("#")
|
2023-03-03 17:27:29 -05:00
|
|
|
return f
|
|
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
|
|
|
|
|
def write_config_toml(writer, section_order, targets, sections):
|
2017-08-26 15:01:48 -07:00
|
|
|
for section in section_order:
|
2024-12-04 23:02:25 +01:00
|
|
|
if section == "target":
|
2017-08-26 15:01:48 -07:00
|
|
|
for target in targets:
|
2023-03-17 10:24:40 -05:00
|
|
|
writer = write_uncommented(targets[target], writer)
|
2017-08-26 15:01:48 -07:00
|
|
|
else:
|
2023-03-17 10:24:40 -05:00
|
|
|
writer = write_uncommented(sections[section], writer)
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2023-04-09 22:50:42 +02:00
|
|
|
def quit_if_file_exists(file):
|
|
|
|
|
if os.path.isfile(file):
|
2023-07-01 22:02:55 -04:00
|
|
|
msg = "Existing '{}' detected. Exiting".format(file)
|
|
|
|
|
|
|
|
|
|
# If the output object directory isn't empty, we can get these errors
|
|
|
|
|
host_objdir = os.environ.get("OBJDIR_ON_HOST")
|
|
|
|
|
if host_objdir is not None:
|
|
|
|
|
msg += "\nIs objdir '{}' clean?".format(host_objdir)
|
|
|
|
|
|
|
|
|
|
err(msg)
|
2023-03-17 10:24:40 -05:00
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
|
2023-03-17 10:24:40 -05:00
|
|
|
if __name__ == "__main__":
|
2025-02-15 19:32:23 +05:30
|
|
|
# If 'bootstrap.toml' already exists, exit the script at this point
|
|
|
|
|
quit_if_file_exists("bootstrap.toml")
|
2023-04-19 14:58:53 +02:00
|
|
|
|
2023-07-09 22:14:48 -05:00
|
|
|
if "GITHUB_ACTIONS" in os.environ:
|
|
|
|
|
print("::group::Configure the build")
|
2023-03-17 10:24:40 -05:00
|
|
|
p("processing command line")
|
|
|
|
|
# Parse all known arguments into a configuration structure that reflects the
|
|
|
|
|
# TOML we're going to write out
|
|
|
|
|
p("")
|
|
|
|
|
section_order, sections, targets = parse_args(sys.argv[1:])
|
|
|
|
|
|
2025-02-15 19:32:23 +05:30
|
|
|
# Now that we've built up our `bootstrap.toml`, write it all out in the same
|
2023-03-17 10:24:40 -05:00
|
|
|
# order that we read it in.
|
|
|
|
|
p("")
|
2025-02-15 19:32:23 +05:30
|
|
|
p("writing `bootstrap.toml` in current directory")
|
|
|
|
|
with bootstrap.output("bootstrap.toml") as f:
|
2023-03-17 10:24:40 -05:00
|
|
|
write_config_toml(f, section_order, targets, sections)
|
|
|
|
|
|
2024-12-04 23:02:25 +01:00
|
|
|
with bootstrap.output("Makefile") as f:
|
|
|
|
|
contents = os.path.join(rust_dir, "src", "bootstrap", "mk", "Makefile.in")
|
2023-03-17 10:24:40 -05:00
|
|
|
contents = open(contents).read()
|
2024-12-04 23:02:25 +01:00
|
|
|
contents = contents.replace("$(CFG_SRC_DIR)", rust_dir + "/")
|
2023-03-17 10:24:40 -05:00
|
|
|
contents = contents.replace("$(CFG_PYTHON)", sys.executable)
|
|
|
|
|
f.write(contents)
|
|
|
|
|
|
|
|
|
|
p("")
|
2025-02-23 19:11:37 +01:00
|
|
|
p("run `{} {}/x.py --help`".format(os.path.basename(sys.executable), rust_dir))
|
2023-07-09 22:14:48 -05:00
|
|
|
if "GITHUB_ACTIONS" in os.environ:
|
|
|
|
|
print("::endgroup::")
|