|
| 1 | +use std::collections::HashMap; |
| 2 | + |
1 | 3 | use serde::{Deserialize, Deserializer};
|
2 | 4 |
|
| 5 | +use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX; |
3 | 6 | use crate::core::config::toml::common::{LlvmLibunwind, SplitDebuginfo, StringOrBool};
|
4 | 7 | use crate::core::config::toml::{Merge, ReplaceOpt};
|
5 |
| -use crate::{HashSet, PathBuf, define_config, exit}; |
| 8 | +use crate::{Config, HashSet, PathBuf, TargetSelection, define_config, exit}; |
6 | 9 |
|
7 | 10 | define_config! {
|
8 | 11 | /// TOML representation of how each build target is configured.
|
@@ -77,3 +80,82 @@ impl Target {
|
77 | 80 | target
|
78 | 81 | }
|
79 | 82 | }
|
| 83 | + |
| 84 | +impl Config { |
| 85 | + pub fn apply_target_config(&mut self, toml_target: Option<HashMap<String, TomlTarget>>) { |
| 86 | + if let Some(t) = toml_target { |
| 87 | + for (triple, cfg) in t { |
| 88 | + let mut target = Target::from_triple(&triple); |
| 89 | + |
| 90 | + if let Some(ref s) = cfg.llvm_config { |
| 91 | + if self.download_rustc_commit.is_some() && triple == *self.build.triple { |
| 92 | + panic!( |
| 93 | + "setting llvm_config for the host is incompatible with download-rustc" |
| 94 | + ); |
| 95 | + } |
| 96 | + target.llvm_config = Some(self.src.join(s)); |
| 97 | + } |
| 98 | + if let Some(patches) = cfg.llvm_has_rust_patches { |
| 99 | + assert!( |
| 100 | + self.submodules == Some(false) || cfg.llvm_config.is_some(), |
| 101 | + "use of `llvm-has-rust-patches` is restricted to cases where either submodules are disabled or llvm-config been provided" |
| 102 | + ); |
| 103 | + target.llvm_has_rust_patches = Some(patches); |
| 104 | + } |
| 105 | + if let Some(ref s) = cfg.llvm_filecheck { |
| 106 | + target.llvm_filecheck = Some(self.src.join(s)); |
| 107 | + } |
| 108 | + target.llvm_libunwind = cfg.llvm_libunwind.as_ref().map(|v| { |
| 109 | + v.parse().unwrap_or_else(|_| { |
| 110 | + panic!("failed to parse target.{triple}.llvm-libunwind") |
| 111 | + }) |
| 112 | + }); |
| 113 | + if let Some(s) = cfg.no_std { |
| 114 | + target.no_std = s; |
| 115 | + } |
| 116 | + target.cc = cfg.cc.map(PathBuf::from); |
| 117 | + target.cxx = cfg.cxx.map(PathBuf::from); |
| 118 | + target.ar = cfg.ar.map(PathBuf::from); |
| 119 | + target.ranlib = cfg.ranlib.map(PathBuf::from); |
| 120 | + target.linker = cfg.linker.map(PathBuf::from); |
| 121 | + target.crt_static = cfg.crt_static; |
| 122 | + target.musl_root = cfg.musl_root.map(PathBuf::from); |
| 123 | + target.musl_libdir = cfg.musl_libdir.map(PathBuf::from); |
| 124 | + target.wasi_root = cfg.wasi_root.map(PathBuf::from); |
| 125 | + target.qemu_rootfs = cfg.qemu_rootfs.map(PathBuf::from); |
| 126 | + target.runner = cfg.runner; |
| 127 | + target.sanitizers = cfg.sanitizers; |
| 128 | + target.profiler = cfg.profiler; |
| 129 | + target.rpath = cfg.rpath; |
| 130 | + target.optimized_compiler_builtins = cfg.optimized_compiler_builtins; |
| 131 | + target.jemalloc = cfg.jemalloc; |
| 132 | + |
| 133 | + if let Some(ref backends) = cfg.codegen_backends { |
| 134 | + let available_backends = ["llvm", "cranelift", "gcc"]; |
| 135 | + |
| 136 | + target.codegen_backends = Some(backends.iter().map(|s| { |
| 137 | + if let Some(backend) = s.strip_prefix(CODEGEN_BACKEND_PREFIX) { |
| 138 | + if available_backends.contains(&backend) { |
| 139 | + panic!("Invalid value '{s}' for 'target.{triple}.codegen-backends'. Instead, please use '{backend}'."); |
| 140 | + } else { |
| 141 | + println!("HELP: '{s}' for 'target.{triple}.codegen-backends' might fail. \ |
| 142 | + Codegen backends are mostly defined without the '{CODEGEN_BACKEND_PREFIX}' prefix. \ |
| 143 | + In this case, it would be referred to as '{backend}'."); |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + s.clone() |
| 148 | + }).collect()); |
| 149 | + } |
| 150 | + |
| 151 | + target.split_debuginfo = cfg.split_debuginfo.as_ref().map(|v| { |
| 152 | + v.parse().unwrap_or_else(|_| { |
| 153 | + panic!("invalid value for target.{triple}.split-debuginfo") |
| 154 | + }) |
| 155 | + }); |
| 156 | + |
| 157 | + self.target_config.insert(TargetSelection::from_user(&triple), target); |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | +} |
0 commit comments