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::{LlvmLibunwind, Merge, ReplaceOpt, SplitDebuginfo, StringOrBool};
15use crate::{CodegenBackendKind, HashSet, PathBuf, define_config, exit};
16
17define_config! {
18    /// TOML representation of how each build target is configured.
19    struct TomlTarget {
20        cc: Option<String> = "cc",
21        cxx: Option<String> = "cxx",
22        ar: Option<String> = "ar",
23        ranlib: Option<String> = "ranlib",
24        default_linker: Option<PathBuf> = "default-linker",
25        linker: Option<String> = "linker",
26        split_debuginfo: Option<String> = "split-debuginfo",
27        llvm_config: Option<String> = "llvm-config",
28        llvm_has_rust_patches: Option<bool> = "llvm-has-rust-patches",
29        llvm_filecheck: Option<String> = "llvm-filecheck",
30        llvm_libunwind: Option<String> = "llvm-libunwind",
31        sanitizers: Option<bool> = "sanitizers",
32        profiler: Option<StringOrBool> = "profiler",
33        rpath: Option<bool> = "rpath",
34        crt_static: Option<bool> = "crt-static",
35        musl_root: Option<String> = "musl-root",
36        musl_libdir: Option<String> = "musl-libdir",
37        wasi_root: Option<String> = "wasi-root",
38        qemu_rootfs: Option<String> = "qemu-rootfs",
39        no_std: Option<bool> = "no-std",
40        codegen_backends: Option<Vec<String>> = "codegen-backends",
41        runner: Option<String> = "runner",
42        optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
43        jemalloc: Option<bool> = "jemalloc",
44    }
45}
46
47/// Per-target configuration stored in the global configuration structure.
48#[derive(Debug, Default, Clone, PartialEq, Eq)]
49pub struct Target {
50    /// Some(path to llvm-config) if using an external LLVM.
51    pub llvm_config: Option<PathBuf>,
52    pub llvm_has_rust_patches: Option<bool>,
53    /// Some(path to FileCheck) if one was specified.
54    pub llvm_filecheck: Option<PathBuf>,
55    pub llvm_libunwind: Option<LlvmLibunwind>,
56    pub cc: Option<PathBuf>,
57    pub cxx: Option<PathBuf>,
58    pub ar: Option<PathBuf>,
59    pub ranlib: Option<PathBuf>,
60    pub default_linker: Option<PathBuf>,
61    pub linker: Option<PathBuf>,
62    pub split_debuginfo: Option<SplitDebuginfo>,
63    pub sanitizers: Option<bool>,
64    pub profiler: Option<StringOrBool>,
65    pub rpath: Option<bool>,
66    pub crt_static: Option<bool>,
67    pub musl_root: Option<PathBuf>,
68    pub musl_libdir: Option<PathBuf>,
69    pub wasi_root: Option<PathBuf>,
70    pub qemu_rootfs: Option<PathBuf>,
71    pub runner: Option<String>,
72    pub no_std: bool,
73    pub codegen_backends: Option<Vec<CodegenBackendKind>>,
74    pub optimized_compiler_builtins: Option<bool>,
75    pub jemalloc: Option<bool>,
76}
77
78impl Target {
79    pub fn from_triple(triple: &str) -> Self {
80        let mut target: Self = Default::default();
81        if !build_helper::targets::target_supports_std(triple) {
82            target.no_std = true;
83        }
84        if triple.contains("emscripten") {
85            target.runner = Some("node".into());
86        }
87        target
88    }
89}