|
4 | 4 | from contextlib import ExitStack, contextmanager |
5 | 5 | from dataclasses import dataclass |
6 | 6 | from pathlib import Path |
7 | | -from typing import Optional, Tuple |
| 7 | +from typing import ClassVar, Dict, Optional, Tuple |
| 8 | + |
| 9 | +import toml |
8 | 10 |
|
9 | 11 | from util import command_runner |
10 | 12 |
|
@@ -193,34 +195,73 @@ def build(self): |
193 | 195 |
|
194 | 196 |
|
195 | 197 | class Alloy(Artefact): |
196 | | - profile: "ExperimentProfile" |
197 | | - |
198 | | - def __init__(self, base: Artefact, profile: "ExperimentProfile"): |
| 198 | + DEFAULT_FLAGS: ClassVar[Dict[str, bool]] = { |
| 199 | + "gc-metrics": False, |
| 200 | + "finalizer-safety-analysis": False, |
| 201 | + "finalizer-elision": True, |
| 202 | + "premature-finalizer-prevention": True, |
| 203 | + "premature-finalizer-prevention-optimize": True, |
| 204 | + "gc-default-allocator": True, |
| 205 | + } |
| 206 | + |
| 207 | + def __init__(self, base: Artefact, profile: "ExperimentProfile", metrics=False): |
199 | 208 | self.__dict__.update(base.__dict__) |
200 | 209 | self.profile = profile |
| 210 | + self.metrics = metrics |
| 211 | + self._config = None |
201 | 212 |
|
202 | 213 | @property |
203 | 214 | def config(self) -> Path: |
204 | | - return ( |
205 | | - Path("alloy").resolve() |
206 | | - / f"{self.profile.full.replace('-','.')}.config.toml" |
207 | | - ) |
| 215 | + if self._config and self._config.exists(): |
| 216 | + return self._config |
| 217 | + |
| 218 | + config = { |
| 219 | + "alloy": self.flags, |
| 220 | + "rust": { |
| 221 | + "codegen-units": 0, |
| 222 | + "optimize": True, |
| 223 | + "debug": False, |
| 224 | + }, |
| 225 | + "build": { |
| 226 | + "install-stage": 2, |
| 227 | + }, |
| 228 | + "llvm": { |
| 229 | + "download-ci-llvm": True, |
| 230 | + }, |
| 231 | + "install": { |
| 232 | + "sysconfdir": "etc", |
| 233 | + }, |
| 234 | + } |
| 235 | + file = self.src / f"{self.name.replace('-','.')}.config.toml" |
| 236 | + with open(file, "w") as f: |
| 237 | + toml.dump(config, f) |
| 238 | + return file |
208 | 239 |
|
209 | 240 | @property |
210 | | - def install_prefix(self) -> Path: |
211 | | - return BIN_DIR / self.repo.name / self.profile.experiment / self.profile.value |
| 241 | + def flags(self): |
| 242 | + return self.DEFAULT_FLAGS.copy() | (self.profile.alloy_flags or {}) |
212 | 243 |
|
213 | 244 | @property |
214 | | - def path(self) -> Path: |
215 | | - return self.install_prefix / "bin" / "rustc" |
| 245 | + def name(self) -> str: |
| 246 | + if not self.flags["gc-default-allocator"]: |
| 247 | + base = "rustc-upstream" |
| 248 | + elif self.flags == self.DEFAULT_FLAGS: |
| 249 | + base = "default" |
| 250 | + else: |
| 251 | + base = self.profile.full |
| 252 | + return f"{base}-metrics" if self.metrics else base |
| 253 | + |
| 254 | + @property |
| 255 | + def install_prefix(self) -> Path: |
| 256 | + return BIN_DIR / self.repo.name / self.name |
216 | 257 |
|
217 | 258 | @property |
218 | 259 | def build_dir(self) -> Path: |
219 | | - return BUILD_DIR / self.repo.name / self.profile.experiment / self.profile.value |
| 260 | + return BUILD_DIR / self.repo.name / self.name |
220 | 261 |
|
221 | 262 | @property |
222 | | - def name(self) -> str: |
223 | | - return f"{self.repo.name} | {self.profile.full}" |
| 263 | + def path(self) -> Path: |
| 264 | + return self.install_prefix / "bin" / "rustc" |
224 | 265 |
|
225 | 266 | @property |
226 | 267 | def installed(self) -> bool: |
@@ -304,7 +345,11 @@ def env(self): |
304 | 345 |
|
305 | 346 | @property |
306 | 347 | def alloy(self) -> "Alloy": |
307 | | - return self.profile.alloy() |
| 348 | + from build import Metric |
| 349 | + |
| 350 | + is_metrics = self.metric == Metric.METRICS |
| 351 | + |
| 352 | + return Alloy(ALLOY, self.profile, is_metrics) |
308 | 353 |
|
309 | 354 | @prepare_build |
310 | 355 | def build(self): |
|
0 commit comments