1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Serialized configuration of a build.
13 //! This module implements parsing `config.mk` and `config.toml` configuration
14 //! files to tweak how the build runs.
16 use std::collections::HashMap;
18 use std::fs::{self, File};
19 use std::io::prelude::*;
20 use std::path::PathBuf;
25 use util::{exe, push_exe_path};
26 use cache::{INTERNER, Interned};
28 /// Global configuration for the entire build and/or bootstrap.
30 /// This structure is derived from a combination of both `config.toml` and
31 /// `config.mk`. As of the time of this writing it's unlikely that `config.toml`
32 /// is used all that much, so this is primarily filled out by `config.mk` which
33 /// is generated from `./configure`.
35 /// Note that this structure is not decoded directly into, but rather it is
36 /// filled out from the decoded forms of the structs below. For documentation
37 /// each field, see the corresponding fields in
38 /// `src/bootstrap/config.toml.example`.
41 pub ccache: Option<String>,
45 pub compiler_docs: bool,
47 pub locked_deps: bool,
49 pub target_config: HashMap<Interned<String>, Target>,
50 pub full_bootstrap: bool,
55 // llvm codegen options
56 pub llvm_assertions: bool,
57 pub llvm_optimize: bool,
58 pub llvm_release_debuginfo: bool,
59 pub llvm_version_check: bool,
60 pub llvm_static_stdcpp: bool,
61 pub llvm_link_shared: bool,
62 pub llvm_targets: Option<String>,
63 pub llvm_experimental_targets: Option<String>,
64 pub llvm_link_jobs: Option<u32>,
65 pub llvm_clean_rebuild: bool,
67 // rust codegen options
68 pub rust_optimize: bool,
69 pub rust_codegen_units: u32,
70 pub rust_debug_assertions: bool,
71 pub rust_debuginfo: bool,
72 pub rust_debuginfo_lines: bool,
73 pub rust_debuginfo_only_std: bool,
75 pub rustc_default_linker: Option<String>,
76 pub rustc_default_ar: Option<String>,
77 pub rust_optimize_tests: bool,
78 pub rust_debuginfo_tests: bool,
79 pub rust_dist_src: bool,
81 pub build: Interned<String>,
82 pub host: Vec<Interned<String>>,
83 pub target: Vec<Interned<String>>,
84 pub local_rebuild: bool,
87 pub dist_sign_folder: Option<PathBuf>,
88 pub dist_upload_addr: Option<String>,
89 pub dist_gpg_password_file: Option<PathBuf>,
92 pub debug_jemalloc: bool,
93 pub use_jemalloc: bool,
94 pub backtrace: bool, // support for RUST_BACKTRACE
97 pub low_priority: bool,
99 pub quiet_tests: bool,
100 // Fallback musl-root for all targets
101 pub musl_root: Option<PathBuf>,
102 pub prefix: Option<PathBuf>,
103 pub sysconfdir: Option<PathBuf>,
104 pub docdir: Option<PathBuf>,
105 pub bindir: Option<PathBuf>,
106 pub libdir: Option<PathBuf>,
107 pub libdir_relative: Option<PathBuf>,
108 pub mandir: Option<PathBuf>,
109 pub codegen_tests: bool,
110 pub nodejs: Option<PathBuf>,
111 pub gdb: Option<PathBuf>,
112 pub python: Option<PathBuf>,
113 pub configure_args: Vec<String>,
114 pub openssl_static: bool,
117 // These are either the stage0 downloaded binaries or the locally installed ones.
118 pub initial_cargo: PathBuf,
119 pub initial_rustc: PathBuf,
123 /// Per-target configuration stored in the global configuration structure.
126 /// Some(path to llvm-config) if using an external LLVM.
127 pub llvm_config: Option<PathBuf>,
128 pub jemalloc: Option<PathBuf>,
129 pub cc: Option<PathBuf>,
130 pub cxx: Option<PathBuf>,
131 pub ndk: Option<PathBuf>,
132 pub musl_root: Option<PathBuf>,
133 pub qemu_rootfs: Option<PathBuf>,
136 /// Structure of the `config.toml` file that configuration is read from.
138 /// This structure uses `Decodable` to automatically decode a TOML configuration
139 /// file into this format, and then this is traversed and written into the above
140 /// `Config` structure.
141 #[derive(Deserialize, Default)]
142 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
144 build: Option<Build>,
145 install: Option<Install>,
148 target: Option<HashMap<String, TomlTarget>>,
152 /// TOML representation of various global build decisions.
153 #[derive(Deserialize, Default, Clone)]
154 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
156 build: Option<String>,
161 cargo: Option<String>,
162 rustc: Option<String>,
163 low_priority: Option<bool>,
164 compiler_docs: Option<bool>,
166 submodules: Option<bool>,
168 locked_deps: Option<bool>,
169 vendor: Option<bool>,
170 nodejs: Option<String>,
171 python: Option<String>,
172 full_bootstrap: Option<bool>,
173 extended: Option<bool>,
174 verbose: Option<usize>,
175 sanitizers: Option<bool>,
176 profiler: Option<bool>,
177 openssl_static: Option<bool>,
180 /// TOML representation of various global install decisions.
181 #[derive(Deserialize, Default, Clone)]
182 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
184 prefix: Option<String>,
185 sysconfdir: Option<String>,
186 docdir: Option<String>,
187 bindir: Option<String>,
188 libdir: Option<String>,
189 mandir: Option<String>,
192 /// TOML representation of how the LLVM build is configured.
193 #[derive(Deserialize, Default)]
194 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
196 ccache: Option<StringOrBool>,
198 assertions: Option<bool>,
199 optimize: Option<bool>,
200 release_debuginfo: Option<bool>,
201 version_check: Option<bool>,
202 static_libstdcpp: Option<bool>,
203 targets: Option<String>,
204 experimental_targets: Option<String>,
205 link_jobs: Option<u32>,
206 clean_rebuild: Option<bool>,
209 #[derive(Deserialize, Default, Clone)]
210 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
212 sign_folder: Option<String>,
213 gpg_password_file: Option<String>,
214 upload_addr: Option<String>,
215 src_tarball: Option<bool>,
218 #[derive(Deserialize)]
225 impl Default for StringOrBool {
226 fn default() -> StringOrBool {
227 StringOrBool::Bool(false)
231 /// TOML representation of how the Rust build is configured.
232 #[derive(Deserialize, Default)]
233 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
235 optimize: Option<bool>,
236 codegen_units: Option<u32>,
237 debug_assertions: Option<bool>,
238 debuginfo: Option<bool>,
239 debuginfo_lines: Option<bool>,
240 debuginfo_only_std: Option<bool>,
241 debug_jemalloc: Option<bool>,
242 use_jemalloc: Option<bool>,
243 backtrace: Option<bool>,
244 default_linker: Option<String>,
245 default_ar: Option<String>,
246 channel: Option<String>,
247 musl_root: Option<String>,
249 optimize_tests: Option<bool>,
250 debuginfo_tests: Option<bool>,
251 codegen_tests: Option<bool>,
254 /// TOML representation of how each build target is configured.
255 #[derive(Deserialize, Default)]
256 #[serde(deny_unknown_fields, rename_all = "kebab-case")]
258 llvm_config: Option<String>,
259 jemalloc: Option<String>,
262 android_ndk: Option<String>,
263 musl_root: Option<String>,
264 qemu_rootfs: Option<String>,
268 pub fn parse(build: &str, file: Option<PathBuf>) -> Config {
269 let mut config = Config::default();
270 config.llvm_optimize = true;
271 config.use_jemalloc = true;
272 config.backtrace = true;
273 config.rust_optimize = true;
274 config.rust_optimize_tests = true;
275 config.submodules = true;
277 config.rust_rpath = true;
278 config.rust_codegen_units = 1;
279 config.build = INTERNER.intern_str(build);
280 config.channel = "dev".to_string();
281 config.codegen_tests = true;
282 config.rust_dist_src = true;
284 let toml = file.map(|file| {
285 let mut f = t!(File::open(&file));
286 let mut contents = String::new();
287 t!(f.read_to_string(&mut contents));
288 match toml::from_str(&contents) {
291 println!("failed to parse TOML configuration '{}': {}",
292 file.display(), err);
296 }).unwrap_or_else(|| TomlConfig::default());
298 let build = toml.build.clone().unwrap_or(Build::default());
299 set(&mut config.build, build.build.clone().map(|x| INTERNER.intern_string(x)));
300 config.host.push(config.build.clone());
301 for host in build.host.iter() {
302 let host = INTERNER.intern_str(host);
303 if !config.host.contains(&host) {
304 config.host.push(host);
307 for target in config.host.iter().cloned()
308 .chain(build.target.iter().map(|s| INTERNER.intern_str(s)))
310 if !config.target.contains(&target) {
311 config.target.push(target);
314 config.nodejs = build.nodejs.map(PathBuf::from);
315 config.gdb = build.gdb.map(PathBuf::from);
316 config.python = build.python.map(PathBuf::from);
317 set(&mut config.low_priority, build.low_priority);
318 set(&mut config.compiler_docs, build.compiler_docs);
319 set(&mut config.docs, build.docs);
320 set(&mut config.submodules, build.submodules);
321 set(&mut config.locked_deps, build.locked_deps);
322 set(&mut config.vendor, build.vendor);
323 set(&mut config.full_bootstrap, build.full_bootstrap);
324 set(&mut config.extended, build.extended);
325 set(&mut config.verbose, build.verbose);
326 set(&mut config.sanitizers, build.sanitizers);
327 set(&mut config.profiler, build.profiler);
328 set(&mut config.openssl_static, build.openssl_static);
330 if let Some(ref install) = toml.install {
331 config.prefix = install.prefix.clone().map(PathBuf::from);
332 config.sysconfdir = install.sysconfdir.clone().map(PathBuf::from);
333 config.docdir = install.docdir.clone().map(PathBuf::from);
334 config.bindir = install.bindir.clone().map(PathBuf::from);
335 config.libdir = install.libdir.clone().map(PathBuf::from);
336 config.mandir = install.mandir.clone().map(PathBuf::from);
339 if let Some(ref llvm) = toml.llvm {
341 Some(StringOrBool::String(ref s)) => {
342 config.ccache = Some(s.to_string())
344 Some(StringOrBool::Bool(true)) => {
345 config.ccache = Some("ccache".to_string());
347 Some(StringOrBool::Bool(false)) | None => {}
349 set(&mut config.ninja, llvm.ninja);
350 set(&mut config.llvm_assertions, llvm.assertions);
351 set(&mut config.llvm_optimize, llvm.optimize);
352 set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);
353 set(&mut config.llvm_version_check, llvm.version_check);
354 set(&mut config.llvm_static_stdcpp, llvm.static_libstdcpp);
355 set(&mut config.llvm_clean_rebuild, llvm.clean_rebuild);
356 config.llvm_targets = llvm.targets.clone();
357 config.llvm_experimental_targets = llvm.experimental_targets.clone();
358 config.llvm_link_jobs = llvm.link_jobs;
361 if let Some(ref rust) = toml.rust {
362 set(&mut config.rust_debug_assertions, rust.debug_assertions);
363 set(&mut config.rust_debuginfo, rust.debuginfo);
364 set(&mut config.rust_debuginfo_lines, rust.debuginfo_lines);
365 set(&mut config.rust_debuginfo_only_std, rust.debuginfo_only_std);
366 set(&mut config.rust_optimize, rust.optimize);
367 set(&mut config.rust_optimize_tests, rust.optimize_tests);
368 set(&mut config.rust_debuginfo_tests, rust.debuginfo_tests);
369 set(&mut config.codegen_tests, rust.codegen_tests);
370 set(&mut config.rust_rpath, rust.rpath);
371 set(&mut config.debug_jemalloc, rust.debug_jemalloc);
372 set(&mut config.use_jemalloc, rust.use_jemalloc);
373 set(&mut config.backtrace, rust.backtrace);
374 set(&mut config.channel, rust.channel.clone());
375 config.rustc_default_linker = rust.default_linker.clone();
376 config.rustc_default_ar = rust.default_ar.clone();
377 config.musl_root = rust.musl_root.clone().map(PathBuf::from);
379 match rust.codegen_units {
380 Some(0) => config.rust_codegen_units = num_cpus::get() as u32,
381 Some(n) => config.rust_codegen_units = n,
386 if let Some(ref t) = toml.target {
387 for (triple, cfg) in t {
388 let mut target = Target::default();
390 if let Some(ref s) = cfg.llvm_config {
391 target.llvm_config = Some(env::current_dir().unwrap().join(s));
393 if let Some(ref s) = cfg.jemalloc {
394 target.jemalloc = Some(env::current_dir().unwrap().join(s));
396 if let Some(ref s) = cfg.android_ndk {
397 target.ndk = Some(env::current_dir().unwrap().join(s));
399 target.cxx = cfg.cxx.clone().map(PathBuf::from);
400 target.cc = cfg.cc.clone().map(PathBuf::from);
401 target.musl_root = cfg.musl_root.clone().map(PathBuf::from);
402 target.qemu_rootfs = cfg.qemu_rootfs.clone().map(PathBuf::from);
404 config.target_config.insert(INTERNER.intern_string(triple.clone()), target);
408 if let Some(ref t) = toml.dist {
409 config.dist_sign_folder = t.sign_folder.clone().map(PathBuf::from);
410 config.dist_gpg_password_file = t.gpg_password_file.clone().map(PathBuf::from);
411 config.dist_upload_addr = t.upload_addr.clone();
412 set(&mut config.rust_dist_src, t.src_tarball);
415 let cwd = t!(env::current_dir());
416 let out = cwd.join("build");
418 let stage0_root = out.join(&config.build).join("stage0/bin");
419 config.initial_rustc = match build.rustc {
420 Some(s) => PathBuf::from(s),
421 None => stage0_root.join(exe("rustc", &config.build)),
423 config.initial_cargo = match build.cargo {
424 Some(s) => PathBuf::from(s),
425 None => stage0_root.join(exe("cargo", &config.build)),
428 // compat with `./configure` while we're still using that
429 if fs::metadata("config.mk").is_ok() {
430 config.update_with_config_mk();
436 /// "Temporary" routine to parse `config.mk` into this configuration.
438 /// While we still have `./configure` this implements the ability to decode
439 /// that configuration into this. This isn't exactly a full-blown makefile
440 /// parser, but hey it gets the job done!
441 fn update_with_config_mk(&mut self) {
442 let mut config = String::new();
443 File::open("config.mk").unwrap().read_to_string(&mut config).unwrap();
444 for line in config.lines() {
445 let mut parts = line.splitn(2, ":=").map(|s| s.trim());
446 let key = parts.next().unwrap();
447 let value = match parts.next() {
448 Some(n) if n.starts_with('\"') => &n[1..n.len() - 1],
454 ($(($name:expr, $val:expr),)*) => {
457 if key == concat!("CFG_ENABLE_", $name) {
461 if key == concat!("CFG_DISABLE_", $name) {
471 ("MANAGE_SUBMODULES", self.submodules),
472 ("COMPILER_DOCS", self.compiler_docs),
474 ("LLVM_ASSERTIONS", self.llvm_assertions),
475 ("LLVM_RELEASE_DEBUGINFO", self.llvm_release_debuginfo),
476 ("OPTIMIZE_LLVM", self.llvm_optimize),
477 ("LLVM_VERSION_CHECK", self.llvm_version_check),
478 ("LLVM_STATIC_STDCPP", self.llvm_static_stdcpp),
479 ("LLVM_LINK_SHARED", self.llvm_link_shared),
480 ("LLVM_CLEAN_REBUILD", self.llvm_clean_rebuild),
481 ("OPTIMIZE", self.rust_optimize),
482 ("DEBUG_ASSERTIONS", self.rust_debug_assertions),
483 ("DEBUGINFO", self.rust_debuginfo),
484 ("DEBUGINFO_LINES", self.rust_debuginfo_lines),
485 ("DEBUGINFO_ONLY_STD", self.rust_debuginfo_only_std),
486 ("JEMALLOC", self.use_jemalloc),
487 ("DEBUG_JEMALLOC", self.debug_jemalloc),
488 ("RPATH", self.rust_rpath),
489 ("OPTIMIZE_TESTS", self.rust_optimize_tests),
490 ("DEBUGINFO_TESTS", self.rust_debuginfo_tests),
491 ("QUIET_TESTS", self.quiet_tests),
492 ("LOCAL_REBUILD", self.local_rebuild),
493 ("NINJA", self.ninja),
494 ("CODEGEN_TESTS", self.codegen_tests),
495 ("LOCKED_DEPS", self.locked_deps),
496 ("VENDOR", self.vendor),
497 ("FULL_BOOTSTRAP", self.full_bootstrap),
498 ("EXTENDED", self.extended),
499 ("SANITIZERS", self.sanitizers),
500 ("PROFILER", self.profiler),
501 ("DIST_SRC", self.rust_dist_src),
502 ("CARGO_OPENSSL_STATIC", self.openssl_static),
506 "CFG_BUILD" if value.len() > 0 => self.build = INTERNER.intern_str(value),
507 "CFG_HOST" if value.len() > 0 => {
508 self.host.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
511 "CFG_TARGET" if value.len() > 0 => {
512 self.target.extend(value.split(" ").map(|s| INTERNER.intern_str(s)));
514 "CFG_EXPERIMENTAL_TARGETS" if value.len() > 0 => {
515 self.llvm_experimental_targets = Some(value.to_string());
517 "CFG_MUSL_ROOT" if value.len() > 0 => {
518 self.musl_root = Some(parse_configure_path(value));
520 "CFG_MUSL_ROOT_X86_64" if value.len() > 0 => {
521 let target = INTERNER.intern_str("x86_64-unknown-linux-musl");
522 let target = self.target_config.entry(target).or_insert(Target::default());
523 target.musl_root = Some(parse_configure_path(value));
525 "CFG_MUSL_ROOT_I686" if value.len() > 0 => {
526 let target = INTERNER.intern_str("i686-unknown-linux-musl");
527 let target = self.target_config.entry(target).or_insert(Target::default());
528 target.musl_root = Some(parse_configure_path(value));
530 "CFG_MUSL_ROOT_ARM" if value.len() > 0 => {
531 let target = INTERNER.intern_str("arm-unknown-linux-musleabi");
532 let target = self.target_config.entry(target).or_insert(Target::default());
533 target.musl_root = Some(parse_configure_path(value));
535 "CFG_MUSL_ROOT_ARMHF" if value.len() > 0 => {
536 let target = INTERNER.intern_str("arm-unknown-linux-musleabihf");
537 let target = self.target_config.entry(target).or_insert(Target::default());
538 target.musl_root = Some(parse_configure_path(value));
540 "CFG_MUSL_ROOT_ARMV7" if value.len() > 0 => {
541 let target = INTERNER.intern_str("armv7-unknown-linux-musleabihf");
542 let target = self.target_config.entry(target).or_insert(Target::default());
543 target.musl_root = Some(parse_configure_path(value));
545 "CFG_DEFAULT_AR" if value.len() > 0 => {
546 self.rustc_default_ar = Some(value.to_string());
548 "CFG_DEFAULT_LINKER" if value.len() > 0 => {
549 self.rustc_default_linker = Some(value.to_string());
551 "CFG_GDB" if value.len() > 0 => {
552 self.gdb = Some(parse_configure_path(value));
554 "CFG_RELEASE_CHANNEL" => {
555 self.channel = value.to_string();
558 self.prefix = Some(PathBuf::from(value));
560 "CFG_SYSCONFDIR" => {
561 self.sysconfdir = Some(PathBuf::from(value));
564 self.docdir = Some(PathBuf::from(value));
567 self.bindir = Some(PathBuf::from(value));
570 self.libdir = Some(PathBuf::from(value));
572 "CFG_LIBDIR_RELATIVE" => {
573 self.libdir_relative = Some(PathBuf::from(value));
576 self.mandir = Some(PathBuf::from(value));
578 "CFG_LLVM_ROOT" if value.len() > 0 => {
579 let target = self.target_config.entry(self.build.clone())
580 .or_insert(Target::default());
581 let root = parse_configure_path(value);
582 target.llvm_config = Some(push_exe_path(root, &["bin", "llvm-config"]));
584 "CFG_JEMALLOC_ROOT" if value.len() > 0 => {
585 let target = self.target_config.entry(self.build.clone())
586 .or_insert(Target::default());
587 target.jemalloc = Some(parse_configure_path(value).join("libjemalloc_pic.a"));
589 "CFG_ARM_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
590 let target = INTERNER.intern_str("arm-linux-androideabi");
591 let target = self.target_config.entry(target).or_insert(Target::default());
592 target.ndk = Some(parse_configure_path(value));
594 "CFG_ARMV7_LINUX_ANDROIDEABI_NDK" if value.len() > 0 => {
595 let target = INTERNER.intern_str("armv7-linux-androideabi");
596 let target = self.target_config.entry(target).or_insert(Target::default());
597 target.ndk = Some(parse_configure_path(value));
599 "CFG_I686_LINUX_ANDROID_NDK" if value.len() > 0 => {
600 let target = INTERNER.intern_str("i686-linux-android");
601 let target = self.target_config.entry(target).or_insert(Target::default());
602 target.ndk = Some(parse_configure_path(value));
604 "CFG_AARCH64_LINUX_ANDROID_NDK" if value.len() > 0 => {
605 let target = INTERNER.intern_str("aarch64-linux-android");
606 let target = self.target_config.entry(target).or_insert(Target::default());
607 target.ndk = Some(parse_configure_path(value));
609 "CFG_X86_64_LINUX_ANDROID_NDK" if value.len() > 0 => {
610 let target = INTERNER.intern_str("x86_64-linux-android");
611 let target = self.target_config.entry(target).or_insert(Target::default());
612 target.ndk = Some(parse_configure_path(value));
614 "CFG_LOCAL_RUST_ROOT" if value.len() > 0 => {
615 let path = parse_configure_path(value);
616 self.initial_rustc = push_exe_path(path.clone(), &["bin", "rustc"]);
617 self.initial_cargo = push_exe_path(path, &["bin", "cargo"]);
619 "CFG_PYTHON" if value.len() > 0 => {
620 let path = parse_configure_path(value);
621 self.python = Some(path);
623 "CFG_ENABLE_CCACHE" if value == "1" => {
624 self.ccache = Some(exe("ccache", &self.build));
626 "CFG_ENABLE_SCCACHE" if value == "1" => {
627 self.ccache = Some(exe("sccache", &self.build));
629 "CFG_CONFIGURE_ARGS" if value.len() > 0 => {
630 self.configure_args = value.split_whitespace()
631 .map(|s| s.to_string())
634 "CFG_QEMU_ARMHF_ROOTFS" if value.len() > 0 => {
635 let target = INTERNER.intern_str("arm-unknown-linux-gnueabihf");
636 let target = self.target_config.entry(target).or_insert(Target::default());
637 target.qemu_rootfs = Some(parse_configure_path(value));
639 "CFG_QEMU_AARCH64_ROOTFS" if value.len() > 0 => {
640 let target = INTERNER.intern_str("aarch64-unknown-linux-gnu");
641 let target = self.target_config.entry(target).or_insert(Target::default());
642 target.qemu_rootfs = Some(parse_configure_path(value));
649 pub fn verbose(&self) -> bool {
653 pub fn very_verbose(&self) -> bool {
659 fn parse_configure_path(path: &str) -> PathBuf {
664 fn parse_configure_path(path: &str) -> PathBuf {
665 // on windows, configure produces unix style paths e.g. /c/some/path but we
666 // only want real windows paths
668 use std::process::Command;
671 // '/' is invalid in windows paths, so we can detect unix paths by the presence of it
672 if !path.contains('/') {
676 let win_path = build_helper::output(Command::new("cygpath").arg("-w").arg(path));
677 let win_path = win_path.trim();
682 fn set<T>(field: &mut T, val: Option<T>) {
683 if let Some(v) = val {