bootstrap/core/config/toml/
target.rs

1//! This module defines the structures and logic for handling target-specific configuration
2//! within the `bootstrap.toml` file. This allows you to customize build settings, tools,
3//! and flags for individual compilation targets.
4//!
5//! It includes:
6//!
7//! * [`TomlTarget`]: This struct directly mirrors the `[target.<triple>]` sections in your
8//!   `bootstrap.toml`. It's used for deserializing raw TOML data for a specific target.
9//! * [`Target`]: This struct represents the processed and validated configuration for a
10//!   build target, which is is stored in the main `Config` structure.
11
12use serde::{Deserialize, Deserializer};
13
14use crate::core::config::{
15    CompilerBuiltins, LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool,
16};
17use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit};
18
19define_config! {
20    /// TOML representation of how each build target is configured.
21    struct TomlTarget {
22        cc: Option<String> = "cc",
23        cxx: Option<String> = "cxx",
24        ar: Option<String> = "ar",
25        ranlib: Option<String> = "ranlib",
26        default_linker: Option<PathBuf> = "default-linker",
27        linker: Option<String> = "linker",
28        split_debuginfo: Option<String> = "split-debuginfo",
29        llvm_config: Option<String> = "llvm-config",
30        llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
31        llvm_filecheck: Option<String> = "llvm-filecheck",
32        llvm_libunwind: Option<String> = "llvm-libunwind",
33        sanitizers: Option<bool> = "sanitizers",
34        profiler: Option<StringOrBool> = "profiler",
35        rpath: Option<bool> = "rpath",
36        crt_static: Option<bool> = "crt-static",
37        musl_root: Option<String> = "musl-root",
38        musl_libdir: Option<String> = "musl-libdir",
39        wasi_root: Option<String> = "wasi-root",
40        qemu_rootfs: Option<String> = "qemu-rootfs",
41        no_std: Option<bool> = "no-std",
42        codegen_backends: Option<Vec<String>> = "codegen-backends",
43        runner: Option<String> = "runner",
44        optimized_compiler_builtins: Option<CompilerBuiltins> = "optimized-compiler-builtins",
45        jemalloc: Option<bool> = "jemalloc",
46    }
47}
48
49/// Per-target configuration stored in the global configuration structure.
50#[derive(Debug, Default, Clone, PartialEq, Eq)]
51pub struct Target {
52    /// Some(path to llvm-config) if using an external LLVM.
53    pub llvm_config: Option<PathBuf>,
54    pub llvm_has_rust_patches: Option<bool>,
55    /// Some(path to FileCheck) if one was specified.
56    pub llvm_filecheck: Option<PathBuf>,
57    pub llvm_libunwind: Option<LlvmLibunwind>,
58    pub cc: Option<PathBuf>,
59    pub cxx: Option<PathBuf>,
60    pub ar: Option<PathBuf>,
61    pub ranlib: Option<PathBuf>,
62    pub default_linker: Option<PathBuf>,
63    pub linker: Option<PathBuf>,
64    pub split_debuginfo: Option<SplitDebuginfo>,
65    pub sanitizers: Option<bool>,
66    pub profiler: Option<StringOrBool>,
67    pub rpath: Option<bool>,
68    pub crt_static: Option<bool>,
69    pub musl_root: Option<PathBuf>,
70    pub musl_libdir: Option<PathBuf>,
71    pub wasi_root: Option<PathBuf>,
72    pub qemu_rootfs: Option<PathBuf>,
73    pub runner: Option<String>,
74    pub no_std: bool,
75    pub codegen_backends: Option<Vec<CodegenBackendKind>>,
76    pub optimized_compiler_builtins: Option<CompilerBuiltins>,
77    pub jemalloc: Option<bool>,
78}
79
80impl Target {
81    pub fn from_triple(triple: &str) -> Self {
82        let mut target: Self = Default::default();
83        if !build_helper::targets::target_supports_std(triple) {
84            target.no_std = true;
85        }
86        if triple.contains("emscripten") {
87            target.runner = Some("node".into());
88        }
89        target
90    }
91}