]> git.lizzy.rs Git - rust.git/blob - src/bootstrap/compile.rs
Auto merge of #56595 - ljedrz:x_py_clippy_fix, r=oli-obk
[rust.git] / src / bootstrap / compile.rs
1 //! Implementation of compiling various phases of the compiler and standard
2 //! library.
3 //!
4 //! This module contains some of the real meat in the rustbuild build system
5 //! which is where Cargo is used to compiler the standard library, libtest, and
6 //! compiler. This module is also responsible for assembling the sysroot as it
7 //! goes along from the output of the previous stage.
8
9 use std::borrow::Cow;
10 use std::env;
11 use std::fs;
12 use std::io::BufReader;
13 use std::io::prelude::*;
14 use std::path::{Path, PathBuf};
15 use std::process::{Command, Stdio, exit};
16 use std::str;
17
18 use build_helper::{output, mtime, t, up_to_date};
19 use filetime::FileTime;
20 use serde::Deserialize;
21 use serde_json;
22
23 use crate::dist;
24 use crate::util::{exe, is_dylib};
25 use crate::{Compiler, Mode, GitRepo};
26 use crate::native;
27
28 use crate::cache::{INTERNER, Interned};
29 use crate::builder::{Step, RunConfig, ShouldRun, Builder};
30
31 #[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
32 pub struct Std {
33     pub target: Interned<String>,
34     pub compiler: Compiler,
35 }
36
37 impl Step for Std {
38     type Output = ();
39     const DEFAULT: bool = true;
40
41     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
42         run.all_krates("std")
43     }
44
45     fn make_run(run: RunConfig<'_>) {
46         run.builder.ensure(Std {
47             compiler: run.builder.compiler(run.builder.top_stage, run.host),
48             target: run.target,
49         });
50     }
51
52     /// Builds the standard library.
53     ///
54     /// This will build the standard library for a particular stage of the build
55     /// using the `compiler` targeting the `target` architecture. The artifacts
56     /// created will also be linked into the sysroot directory.
57     fn run(self, builder: &Builder<'_>) {
58         let target = self.target;
59         let compiler = self.compiler;
60
61         if builder.config.keep_stage.contains(&compiler.stage) {
62             builder.info("Warning: Using a potentially old libstd. This may not behave well.");
63             builder.ensure(StdLink {
64                 compiler,
65                 target_compiler: compiler,
66                 target,
67             });
68             return;
69         }
70
71         builder.ensure(StartupObjects { compiler, target });
72
73         if builder.force_use_stage1(compiler, target) {
74             let from = builder.compiler(1, builder.config.build);
75             builder.ensure(Std {
76                 compiler: from,
77                 target,
78             });
79             builder.info(&format!("Uplifting stage1 std ({} -> {})", from.host, target));
80
81             // Even if we're not building std this stage, the new sysroot must
82             // still contain the third party objects needed by various targets.
83             copy_third_party_objects(builder, &compiler, target);
84
85             builder.ensure(StdLink {
86                 compiler: from,
87                 target_compiler: compiler,
88                 target,
89             });
90             return;
91         }
92
93         copy_third_party_objects(builder, &compiler, target);
94
95         let mut cargo = builder.cargo(compiler, Mode::Std, target, "build");
96         std_cargo(builder, &compiler, target, &mut cargo);
97
98         let _folder = builder.fold_output(|| format!("stage{}-std", compiler.stage));
99         builder.info(&format!("Building stage{} std artifacts ({} -> {})", compiler.stage,
100                 &compiler.host, target));
101         run_cargo(builder,
102                   &mut cargo,
103                   vec![],
104                   &libstd_stamp(builder, compiler, target),
105                   false);
106
107         builder.ensure(StdLink {
108             compiler: builder.compiler(compiler.stage, builder.config.build),
109             target_compiler: compiler,
110             target,
111         });
112     }
113 }
114
115 /// Copies third pary objects needed by various targets.
116 fn copy_third_party_objects(builder: &Builder<'_>, compiler: &Compiler, target: Interned<String>) {
117     let libdir = builder.sysroot_libdir(*compiler, target);
118
119     // Copies the crt(1,i,n).o startup objects
120     //
121     // Since musl supports fully static linking, we can cross link for it even
122     // with a glibc-targeting toolchain, given we have the appropriate startup
123     // files. As those shipped with glibc won't work, copy the ones provided by
124     // musl so we have them on linux-gnu hosts.
125     if target.contains("musl") {
126         for &obj in &["crt1.o", "crti.o", "crtn.o"] {
127             builder.copy(
128                 &builder.musl_root(target).unwrap().join("lib").join(obj),
129                 &libdir.join(obj),
130             );
131         }
132     } else if target.ends_with("-wasi") {
133         for &obj in &["crt1.o"] {
134             builder.copy(
135                 &builder.wasi_root(target).unwrap().join("lib/wasm32-wasi").join(obj),
136                 &libdir.join(obj),
137             );
138         }
139     }
140
141     // Copies libunwind.a compiled to be linked wit x86_64-fortanix-unknown-sgx.
142     //
143     // This target needs to be linked to Fortanix's port of llvm's libunwind.
144     // libunwind requires support for rwlock and printing to stderr,
145     // which is provided by std for this target.
146     if target == "x86_64-fortanix-unknown-sgx" {
147         let src_path_env = "X86_FORTANIX_SGX_LIBS";
148         let obj = "libunwind.a";
149         let src = env::var(src_path_env).expect(&format!("{} not found in env", src_path_env));
150         let src = Path::new(&src).join(obj);
151         builder.copy(&src, &libdir.join(obj));
152     }
153 }
154
155 /// Configure cargo to compile the standard library, adding appropriate env vars
156 /// and such.
157 pub fn std_cargo(builder: &Builder<'_>,
158                  compiler: &Compiler,
159                  target: Interned<String>,
160                  cargo: &mut Command) {
161     if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
162         cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
163     }
164
165     // Determine if we're going to compile in optimized C intrinsics to
166     // the `compiler-builtins` crate. These intrinsics live in LLVM's
167     // `compiler-rt` repository, but our `src/llvm-project` submodule isn't
168     // always checked out, so we need to conditionally look for this. (e.g. if
169     // an external LLVM is used we skip the LLVM submodule checkout).
170     //
171     // Note that this shouldn't affect the correctness of `compiler-builtins`,
172     // but only its speed. Some intrinsics in C haven't been translated to Rust
173     // yet but that's pretty rare. Other intrinsics have optimized
174     // implementations in C which have only had slower versions ported to Rust,
175     // so we favor the C version where we can, but it's not critical.
176     //
177     // If `compiler-rt` is available ensure that the `c` feature of the
178     // `compiler-builtins` crate is enabled and it's configured to learn where
179     // `compiler-rt` is located.
180     let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
181     let compiler_builtins_c_feature = if compiler_builtins_root.exists() {
182         cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
183         " compiler-builtins-c".to_string()
184     } else {
185         String::new()
186     };
187
188     if builder.no_std(target) == Some(true) {
189         let mut features = "compiler-builtins-mem".to_string();
190         features.push_str(&compiler_builtins_c_feature);
191
192         // for no-std targets we only compile a few no_std crates
193         cargo
194             .args(&["-p", "alloc"])
195             .arg("--manifest-path")
196             .arg(builder.src.join("src/liballoc/Cargo.toml"))
197             .arg("--features")
198             .arg("compiler-builtins-mem compiler-builtins-c");
199     } else {
200         let mut features = builder.std_features();
201         features.push_str(&compiler_builtins_c_feature);
202
203         if compiler.stage != 0 && builder.config.sanitizers {
204             // This variable is used by the sanitizer runtime crates, e.g.
205             // rustc_lsan, to build the sanitizer runtime from C code
206             // When this variable is missing, those crates won't compile the C code,
207             // so we don't set this variable during stage0 where llvm-config is
208             // missing
209             // We also only build the runtimes when --enable-sanitizers (or its
210             // config.toml equivalent) is used
211             let llvm_config = builder.ensure(native::Llvm {
212                 target: builder.config.build,
213                 emscripten: false,
214             });
215             cargo.env("LLVM_CONFIG", llvm_config);
216         }
217
218         cargo.arg("--features").arg(features)
219             .arg("--manifest-path")
220             .arg(builder.src.join("src/libstd/Cargo.toml"));
221
222         if target.contains("musl") {
223             if let Some(p) = builder.musl_root(target) {
224                 cargo.env("MUSL_ROOT", p);
225             }
226         }
227
228         if target.ends_with("-wasi") {
229             if let Some(p) = builder.wasi_root(target) {
230                 cargo.env("WASI_ROOT", p);
231             }
232         }
233     }
234 }
235
236 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
237 struct StdLink {
238     pub compiler: Compiler,
239     pub target_compiler: Compiler,
240     pub target: Interned<String>,
241 }
242
243 impl Step for StdLink {
244     type Output = ();
245
246     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
247         run.never()
248     }
249
250     /// Link all libstd rlibs/dylibs into the sysroot location.
251     ///
252     /// Links those artifacts generated by `compiler` to the `stage` compiler's
253     /// sysroot for the specified `host` and `target`.
254     ///
255     /// Note that this assumes that `compiler` has already generated the libstd
256     /// libraries for `target`, and this method will find them in the relevant
257     /// output directory.
258     fn run(self, builder: &Builder<'_>) {
259         let compiler = self.compiler;
260         let target_compiler = self.target_compiler;
261         let target = self.target;
262         builder.info(&format!("Copying stage{} std from stage{} ({} -> {} / {})",
263                 target_compiler.stage,
264                 compiler.stage,
265                 &compiler.host,
266                 target_compiler.host,
267                 target));
268         let libdir = builder.sysroot_libdir(target_compiler, target);
269         let hostdir = builder.sysroot_libdir(target_compiler, compiler.host);
270         add_to_sysroot(builder, &libdir, &hostdir, &libstd_stamp(builder, compiler, target));
271
272         if builder.config.sanitizers && compiler.stage != 0 && target == "x86_64-apple-darwin" {
273             // The sanitizers are only built in stage1 or above, so the dylibs will
274             // be missing in stage0 and causes panic. See the `std()` function above
275             // for reason why the sanitizers are not built in stage0.
276             copy_apple_sanitizer_dylibs(builder, &builder.native_dir(target), "osx", &libdir);
277         }
278
279         builder.cargo(target_compiler, Mode::ToolStd, target, "clean");
280     }
281 }
282
283 fn copy_apple_sanitizer_dylibs(
284     builder: &Builder<'_>,
285     native_dir: &Path,
286     platform: &str,
287     into: &Path,
288 ) {
289     for &sanitizer in &["asan", "tsan"] {
290         let filename = format!("lib__rustc__clang_rt.{}_{}_dynamic.dylib", sanitizer, platform);
291         let mut src_path = native_dir.join(sanitizer);
292         src_path.push("build");
293         src_path.push("lib");
294         src_path.push("darwin");
295         src_path.push(&filename);
296         builder.copy(&src_path, &into.join(filename));
297     }
298 }
299
300 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
301 pub struct StartupObjects {
302     pub compiler: Compiler,
303     pub target: Interned<String>,
304 }
305
306 impl Step for StartupObjects {
307     type Output = ();
308
309     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
310         run.path("src/rtstartup")
311     }
312
313     fn make_run(run: RunConfig<'_>) {
314         run.builder.ensure(StartupObjects {
315             compiler: run.builder.compiler(run.builder.top_stage, run.host),
316             target: run.target,
317         });
318     }
319
320     /// Builds and prepare startup objects like rsbegin.o and rsend.o
321     ///
322     /// These are primarily used on Windows right now for linking executables/dlls.
323     /// They don't require any library support as they're just plain old object
324     /// files, so we just use the nightly snapshot compiler to always build them (as
325     /// no other compilers are guaranteed to be available).
326     fn run(self, builder: &Builder<'_>) {
327         let for_compiler = self.compiler;
328         let target = self.target;
329         if !target.contains("pc-windows-gnu") {
330             return
331         }
332
333         let src_dir = &builder.src.join("src/rtstartup");
334         let dst_dir = &builder.native_dir(target).join("rtstartup");
335         let sysroot_dir = &builder.sysroot_libdir(for_compiler, target);
336         t!(fs::create_dir_all(dst_dir));
337
338         for file in &["rsbegin", "rsend"] {
339             let src_file = &src_dir.join(file.to_string() + ".rs");
340             let dst_file = &dst_dir.join(file.to_string() + ".o");
341             if !up_to_date(src_file, dst_file) {
342                 let mut cmd = Command::new(&builder.initial_rustc);
343                 builder.run(cmd.env("RUSTC_BOOTSTRAP", "1")
344                             .arg("--cfg").arg("stage0")
345                             .arg("--target").arg(target)
346                             .arg("--emit=obj")
347                             .arg("-o").arg(dst_file)
348                             .arg(src_file));
349             }
350
351             builder.copy(dst_file, &sysroot_dir.join(file.to_string() + ".o"));
352         }
353
354         for obj in ["crt2.o", "dllcrt2.o"].iter() {
355             let src = compiler_file(builder,
356                                     builder.cc(target),
357                                     target,
358                                     obj);
359             builder.copy(&src, &sysroot_dir.join(obj));
360         }
361     }
362 }
363
364 #[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
365 pub struct Test {
366     pub target: Interned<String>,
367     pub compiler: Compiler,
368 }
369
370 impl Step for Test {
371     type Output = ();
372     const DEFAULT: bool = true;
373
374     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
375         run.all_krates("test")
376     }
377
378     fn make_run(run: RunConfig<'_>) {
379         run.builder.ensure(Test {
380             compiler: run.builder.compiler(run.builder.top_stage, run.host),
381             target: run.target,
382         });
383     }
384
385     /// Builds libtest.
386     ///
387     /// This will build libtest and supporting libraries for a particular stage of
388     /// the build using the `compiler` targeting the `target` architecture. The
389     /// artifacts created will also be linked into the sysroot directory.
390     fn run(self, builder: &Builder<'_>) {
391         let target = self.target;
392         let compiler = self.compiler;
393
394         builder.ensure(Std { compiler, target });
395
396         if builder.config.keep_stage.contains(&compiler.stage) {
397             builder.info("Warning: Using a potentially old libtest. This may not behave well.");
398             builder.ensure(TestLink {
399                 compiler,
400                 target_compiler: compiler,
401                 target,
402             });
403             return;
404         }
405
406         if builder.force_use_stage1(compiler, target) {
407             builder.ensure(Test {
408                 compiler: builder.compiler(1, builder.config.build),
409                 target,
410             });
411             builder.info(
412                 &format!("Uplifting stage1 test ({} -> {})", builder.config.build, target));
413             builder.ensure(TestLink {
414                 compiler: builder.compiler(1, builder.config.build),
415                 target_compiler: compiler,
416                 target,
417             });
418             return;
419         }
420
421         let mut cargo = builder.cargo(compiler, Mode::Test, target, "build");
422         test_cargo(builder, &compiler, target, &mut cargo);
423
424         let _folder = builder.fold_output(|| format!("stage{}-test", compiler.stage));
425         builder.info(&format!("Building stage{} test artifacts ({} -> {})", compiler.stage,
426                 &compiler.host, target));
427         run_cargo(builder,
428                   &mut cargo,
429                   vec![],
430                   &libtest_stamp(builder, compiler, target),
431                   false);
432
433         builder.ensure(TestLink {
434             compiler: builder.compiler(compiler.stage, builder.config.build),
435             target_compiler: compiler,
436             target,
437         });
438     }
439 }
440
441 /// Same as `std_cargo`, but for libtest
442 pub fn test_cargo(builder: &Builder<'_>,
443                   _compiler: &Compiler,
444                   _target: Interned<String>,
445                   cargo: &mut Command) {
446     if let Some(target) = env::var_os("MACOSX_STD_DEPLOYMENT_TARGET") {
447         cargo.env("MACOSX_DEPLOYMENT_TARGET", target);
448     }
449     cargo.arg("--manifest-path")
450         .arg(builder.src.join("src/libtest/Cargo.toml"));
451 }
452
453 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
454 pub struct TestLink {
455     pub compiler: Compiler,
456     pub target_compiler: Compiler,
457     pub target: Interned<String>,
458 }
459
460 impl Step for TestLink {
461     type Output = ();
462
463     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
464         run.never()
465     }
466
467     /// Same as `std_link`, only for libtest
468     fn run(self, builder: &Builder<'_>) {
469         let compiler = self.compiler;
470         let target_compiler = self.target_compiler;
471         let target = self.target;
472         builder.info(&format!("Copying stage{} test from stage{} ({} -> {} / {})",
473                 target_compiler.stage,
474                 compiler.stage,
475                 &compiler.host,
476                 target_compiler.host,
477                 target));
478         add_to_sysroot(
479             builder,
480             &builder.sysroot_libdir(target_compiler, target),
481             &builder.sysroot_libdir(target_compiler, compiler.host),
482             &libtest_stamp(builder, compiler, target)
483         );
484
485         builder.cargo(target_compiler, Mode::ToolTest, target, "clean");
486     }
487 }
488
489 #[derive(Debug, PartialOrd, Ord, Copy, Clone, PartialEq, Eq, Hash)]
490 pub struct Rustc {
491     pub target: Interned<String>,
492     pub compiler: Compiler,
493 }
494
495 impl Step for Rustc {
496     type Output = ();
497     const ONLY_HOSTS: bool = true;
498     const DEFAULT: bool = true;
499
500     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
501         run.all_krates("rustc-main")
502     }
503
504     fn make_run(run: RunConfig<'_>) {
505         run.builder.ensure(Rustc {
506             compiler: run.builder.compiler(run.builder.top_stage, run.host),
507             target: run.target,
508         });
509     }
510
511     /// Builds the compiler.
512     ///
513     /// This will build the compiler for a particular stage of the build using
514     /// the `compiler` targeting the `target` architecture. The artifacts
515     /// created will also be linked into the sysroot directory.
516     fn run(self, builder: &Builder<'_>) {
517         let compiler = self.compiler;
518         let target = self.target;
519
520         builder.ensure(Test { compiler, target });
521
522         if builder.config.keep_stage.contains(&compiler.stage) {
523             builder.info("Warning: Using a potentially old librustc. This may not behave well.");
524             builder.ensure(RustcLink {
525                 compiler,
526                 target_compiler: compiler,
527                 target,
528             });
529             return;
530         }
531
532         if builder.force_use_stage1(compiler, target) {
533             builder.ensure(Rustc {
534                 compiler: builder.compiler(1, builder.config.build),
535                 target,
536             });
537             builder.info(&format!("Uplifting stage1 rustc ({} -> {})",
538                 builder.config.build, target));
539             builder.ensure(RustcLink {
540                 compiler: builder.compiler(1, builder.config.build),
541                 target_compiler: compiler,
542                 target,
543             });
544             return;
545         }
546
547         // Ensure that build scripts and proc macros have a std / libproc_macro to link against.
548         builder.ensure(Test {
549             compiler: builder.compiler(self.compiler.stage, builder.config.build),
550             target: builder.config.build,
551         });
552
553         let mut cargo = builder.cargo(compiler, Mode::Rustc, target, "build");
554         rustc_cargo(builder, &mut cargo);
555
556         let _folder = builder.fold_output(|| format!("stage{}-rustc", compiler.stage));
557         builder.info(&format!("Building stage{} compiler artifacts ({} -> {})",
558                  compiler.stage, &compiler.host, target));
559         run_cargo(builder,
560                   &mut cargo,
561                   vec![],
562                   &librustc_stamp(builder, compiler, target),
563                   false);
564
565         builder.ensure(RustcLink {
566             compiler: builder.compiler(compiler.stage, builder.config.build),
567             target_compiler: compiler,
568             target,
569         });
570     }
571 }
572
573 pub fn rustc_cargo(builder: &Builder<'_>, cargo: &mut Command) {
574     cargo.arg("--features").arg(builder.rustc_features())
575          .arg("--manifest-path")
576          .arg(builder.src.join("src/rustc/Cargo.toml"));
577     rustc_cargo_env(builder, cargo);
578 }
579
580 pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Command) {
581     // Set some configuration variables picked up by build scripts and
582     // the compiler alike
583     cargo.env("CFG_RELEASE", builder.rust_release())
584          .env("CFG_RELEASE_CHANNEL", &builder.config.channel)
585          .env("CFG_VERSION", builder.rust_version())
586          .env("CFG_PREFIX", builder.config.prefix.clone().unwrap_or_default())
587          .env("CFG_CODEGEN_BACKENDS_DIR", &builder.config.rust_codegen_backends_dir);
588
589     let libdir_relative = builder.config.libdir_relative().unwrap_or(Path::new("lib"));
590     cargo.env("CFG_LIBDIR_RELATIVE", libdir_relative);
591
592     if let Some(ref ver_date) = builder.rust_info.commit_date() {
593         cargo.env("CFG_VER_DATE", ver_date);
594     }
595     if let Some(ref ver_hash) = builder.rust_info.sha() {
596         cargo.env("CFG_VER_HASH", ver_hash);
597     }
598     if !builder.unstable_features() {
599         cargo.env("CFG_DISABLE_UNSTABLE_FEATURES", "1");
600     }
601     if let Some(ref s) = builder.config.rustc_default_linker {
602         cargo.env("CFG_DEFAULT_LINKER", s);
603     }
604     if builder.config.rustc_parallel {
605         cargo.env("RUSTC_PARALLEL_COMPILER", "1");
606     }
607     if builder.config.rust_verify_llvm_ir {
608         cargo.env("RUSTC_VERIFY_LLVM_IR", "1");
609     }
610 }
611
612 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
613 struct RustcLink {
614     pub compiler: Compiler,
615     pub target_compiler: Compiler,
616     pub target: Interned<String>,
617 }
618
619 impl Step for RustcLink {
620     type Output = ();
621
622     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
623         run.never()
624     }
625
626     /// Same as `std_link`, only for librustc
627     fn run(self, builder: &Builder<'_>) {
628         let compiler = self.compiler;
629         let target_compiler = self.target_compiler;
630         let target = self.target;
631         builder.info(&format!("Copying stage{} rustc from stage{} ({} -> {} / {})",
632                  target_compiler.stage,
633                  compiler.stage,
634                  &compiler.host,
635                  target_compiler.host,
636                  target));
637         add_to_sysroot(
638             builder,
639             &builder.sysroot_libdir(target_compiler, target),
640             &builder.sysroot_libdir(target_compiler, compiler.host),
641             &librustc_stamp(builder, compiler, target)
642         );
643         builder.cargo(target_compiler, Mode::ToolRustc, target, "clean");
644     }
645 }
646
647 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
648 pub struct CodegenBackend {
649     pub compiler: Compiler,
650     pub target: Interned<String>,
651     pub backend: Interned<String>,
652 }
653
654 impl Step for CodegenBackend {
655     type Output = ();
656     const ONLY_HOSTS: bool = true;
657     const DEFAULT: bool = true;
658
659     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
660         run.all_krates("rustc_codegen_llvm")
661     }
662
663     fn make_run(run: RunConfig<'_>) {
664         let backend = run.builder.config.rust_codegen_backends.get(0);
665         let backend = backend.cloned().unwrap_or_else(|| {
666             INTERNER.intern_str("llvm")
667         });
668         run.builder.ensure(CodegenBackend {
669             compiler: run.builder.compiler(run.builder.top_stage, run.host),
670             target: run.target,
671             backend,
672         });
673     }
674
675     fn run(self, builder: &Builder<'_>) {
676         let compiler = self.compiler;
677         let target = self.target;
678         let backend = self.backend;
679
680         builder.ensure(Rustc { compiler, target });
681
682         if builder.config.keep_stage.contains(&compiler.stage) {
683             builder.info("Warning: Using a potentially old codegen backend. \
684                 This may not behave well.");
685             // Codegen backends are linked separately from this step today, so we don't do
686             // anything here.
687             return;
688         }
689
690         if builder.force_use_stage1(compiler, target) {
691             builder.ensure(CodegenBackend {
692                 compiler: builder.compiler(1, builder.config.build),
693                 target,
694                 backend,
695             });
696             return;
697         }
698
699         let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
700
701         let mut cargo = builder.cargo(compiler, Mode::Codegen, target, "build");
702         cargo.arg("--manifest-path")
703             .arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml"));
704         rustc_cargo_env(builder, &mut cargo);
705
706         let features = build_codegen_backend(&builder, &mut cargo, &compiler, target, backend);
707
708         let tmp_stamp = out_dir.join(".tmp.stamp");
709
710         let _folder = builder.fold_output(|| format!("stage{}-rustc_codegen_llvm", compiler.stage));
711         let files = run_cargo(builder,
712                               cargo.arg("--features").arg(features),
713                               vec![],
714                               &tmp_stamp,
715                               false);
716         if builder.config.dry_run {
717             return;
718         }
719         let mut files = files.into_iter()
720             .filter(|f| {
721                 let filename = f.file_name().unwrap().to_str().unwrap();
722                 is_dylib(filename) && filename.contains("rustc_codegen_llvm-")
723             });
724         let codegen_backend = match files.next() {
725             Some(f) => f,
726             None => panic!("no dylibs built for codegen backend?"),
727         };
728         if let Some(f) = files.next() {
729             panic!("codegen backend built two dylibs:\n{}\n{}",
730                    codegen_backend.display(),
731                    f.display());
732         }
733         let stamp = codegen_backend_stamp(builder, compiler, target, backend);
734         let codegen_backend = codegen_backend.to_str().unwrap();
735         t!(fs::write(&stamp, &codegen_backend));
736     }
737 }
738
739 pub fn build_codegen_backend(builder: &Builder<'_>,
740                              cargo: &mut Command,
741                              compiler: &Compiler,
742                              target: Interned<String>,
743                              backend: Interned<String>) -> String {
744     let mut features = String::new();
745
746     match &*backend {
747         "llvm" | "emscripten" => {
748             // Build LLVM for our target. This will implicitly build the
749             // host LLVM if necessary.
750             let llvm_config = builder.ensure(native::Llvm {
751                 target,
752                 emscripten: backend == "emscripten",
753             });
754
755             if backend == "emscripten" {
756                 features.push_str(" emscripten");
757             }
758
759             builder.info(&format!("Building stage{} codegen artifacts ({} -> {}, {})",
760                      compiler.stage, &compiler.host, target, backend));
761
762             // Pass down configuration from the LLVM build into the build of
763             // librustc_llvm and librustc_codegen_llvm.
764             if builder.is_rust_llvm(target) && backend != "emscripten" {
765                 cargo.env("LLVM_RUSTLLVM", "1");
766             }
767
768             cargo.env("LLVM_CONFIG", &llvm_config);
769             if backend != "emscripten" {
770                 let target_config = builder.config.target_config.get(&target);
771                 if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) {
772                     cargo.env("CFG_LLVM_ROOT", s);
773                 }
774             }
775             // Building with a static libstdc++ is only supported on linux right now,
776             // not for MSVC or macOS
777             if builder.config.llvm_static_stdcpp &&
778                !target.contains("freebsd") &&
779                !target.contains("windows") &&
780                !target.contains("apple") {
781                 let file = compiler_file(builder,
782                                          builder.cxx(target).unwrap(),
783                                          target,
784                                          "libstdc++.a");
785                 cargo.env("LLVM_STATIC_STDCPP", file);
786             }
787             if builder.config.llvm_link_shared ||
788                 (builder.config.llvm_thin_lto && backend != "emscripten")
789             {
790                 cargo.env("LLVM_LINK_SHARED", "1");
791             }
792             if builder.config.llvm_use_libcxx {
793                 cargo.env("LLVM_USE_LIBCXX", "1");
794             }
795         }
796         _ => panic!("unknown backend: {}", backend),
797     }
798
799     features
800 }
801
802 /// Creates the `codegen-backends` folder for a compiler that's about to be
803 /// assembled as a complete compiler.
804 ///
805 /// This will take the codegen artifacts produced by `compiler` and link them
806 /// into an appropriate location for `target_compiler` to be a functional
807 /// compiler.
808 fn copy_codegen_backends_to_sysroot(builder: &Builder<'_>,
809                                     compiler: Compiler,
810                                     target_compiler: Compiler) {
811     let target = target_compiler.host;
812
813     // Note that this step is different than all the other `*Link` steps in
814     // that it's not assembling a bunch of libraries but rather is primarily
815     // moving the codegen backend into place. The codegen backend of rustc is
816     // not linked into the main compiler by default but is rather dynamically
817     // selected at runtime for inclusion.
818     //
819     // Here we're looking for the output dylib of the `CodegenBackend` step and
820     // we're copying that into the `codegen-backends` folder.
821     let dst = builder.sysroot_codegen_backends(target_compiler);
822     t!(fs::create_dir_all(&dst));
823
824     if builder.config.dry_run {
825         return;
826     }
827
828     for backend in builder.config.rust_codegen_backends.iter() {
829         let stamp = codegen_backend_stamp(builder, compiler, target, *backend);
830         let dylib = t!(fs::read_to_string(&stamp));
831         let file = Path::new(&dylib);
832         let filename = file.file_name().unwrap().to_str().unwrap();
833         // change `librustc_codegen_llvm-xxxxxx.so` to `librustc_codegen_llvm-llvm.so`
834         let target_filename = {
835             let dash = filename.find('-').unwrap();
836             let dot = filename.find('.').unwrap();
837             format!("{}-{}{}",
838                     &filename[..dash],
839                     backend,
840                     &filename[dot..])
841         };
842         builder.copy(&file, &dst.join(target_filename));
843     }
844 }
845
846 fn copy_lld_to_sysroot(builder: &Builder<'_>,
847                        target_compiler: Compiler,
848                        lld_install_root: &Path) {
849     let target = target_compiler.host;
850
851     let dst = builder.sysroot_libdir(target_compiler, target)
852         .parent()
853         .unwrap()
854         .join("bin");
855     t!(fs::create_dir_all(&dst));
856
857     let src_exe = exe("lld", &target);
858     let dst_exe = exe("rust-lld", &target);
859     // we prepend this bin directory to the user PATH when linking Rust binaries. To
860     // avoid shadowing the system LLD we rename the LLD we provide to `rust-lld`.
861     builder.copy(&lld_install_root.join("bin").join(&src_exe), &dst.join(&dst_exe));
862 }
863
864 /// Cargo's output path for the standard library in a given stage, compiled
865 /// by a particular compiler for the specified target.
866 pub fn libstd_stamp(
867     builder: &Builder<'_>,
868     compiler: Compiler,
869     target: Interned<String>,
870 ) -> PathBuf {
871     builder.cargo_out(compiler, Mode::Std, target).join(".libstd.stamp")
872 }
873
874 /// Cargo's output path for libtest in a given stage, compiled by a particular
875 /// compiler for the specified target.
876 pub fn libtest_stamp(
877     builder: &Builder<'_>,
878     compiler: Compiler,
879     target: Interned<String>,
880 ) -> PathBuf {
881     builder.cargo_out(compiler, Mode::Test, target).join(".libtest.stamp")
882 }
883
884 /// Cargo's output path for librustc in a given stage, compiled by a particular
885 /// compiler for the specified target.
886 pub fn librustc_stamp(
887     builder: &Builder<'_>,
888     compiler: Compiler,
889     target: Interned<String>,
890 ) -> PathBuf {
891     builder.cargo_out(compiler, Mode::Rustc, target).join(".librustc.stamp")
892 }
893
894 /// Cargo's output path for librustc_codegen_llvm in a given stage, compiled by a particular
895 /// compiler for the specified target and backend.
896 fn codegen_backend_stamp(builder: &Builder<'_>,
897                          compiler: Compiler,
898                          target: Interned<String>,
899                          backend: Interned<String>) -> PathBuf {
900     builder.cargo_out(compiler, Mode::Codegen, target)
901         .join(format!(".librustc_codegen_llvm-{}.stamp", backend))
902 }
903
904 pub fn compiler_file(
905     builder: &Builder<'_>,
906     compiler: &Path,
907     target: Interned<String>,
908     file: &str,
909 ) -> PathBuf {
910     let mut cmd = Command::new(compiler);
911     cmd.args(builder.cflags(target, GitRepo::Rustc));
912     cmd.arg(format!("-print-file-name={}", file));
913     let out = output(&mut cmd);
914     PathBuf::from(out.trim())
915 }
916
917 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
918 pub struct Sysroot {
919     pub compiler: Compiler,
920 }
921
922 impl Step for Sysroot {
923     type Output = Interned<PathBuf>;
924
925     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
926         run.never()
927     }
928
929     /// Returns the sysroot for the `compiler` specified that *this build system
930     /// generates*.
931     ///
932     /// That is, the sysroot for the stage0 compiler is not what the compiler
933     /// thinks it is by default, but it's the same as the default for stages
934     /// 1-3.
935     fn run(self, builder: &Builder<'_>) -> Interned<PathBuf> {
936         let compiler = self.compiler;
937         let sysroot = if compiler.stage == 0 {
938             builder.out.join(&compiler.host).join("stage0-sysroot")
939         } else {
940             builder.out.join(&compiler.host).join(format!("stage{}", compiler.stage))
941         };
942         let _ = fs::remove_dir_all(&sysroot);
943         t!(fs::create_dir_all(&sysroot));
944         INTERNER.intern_path(sysroot)
945     }
946 }
947
948 #[derive(Debug, Copy, PartialOrd, Ord, Clone, PartialEq, Eq, Hash)]
949 pub struct Assemble {
950     /// The compiler which we will produce in this step. Assemble itself will
951     /// take care of ensuring that the necessary prerequisites to do so exist,
952     /// that is, this target can be a stage2 compiler and Assemble will build
953     /// previous stages for you.
954     pub target_compiler: Compiler,
955 }
956
957 impl Step for Assemble {
958     type Output = Compiler;
959
960     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
961         run.never()
962     }
963
964     /// Prepare a new compiler from the artifacts in `stage`
965     ///
966     /// This will assemble a compiler in `build/$host/stage$stage`. The compiler
967     /// must have been previously produced by the `stage - 1` builder.build
968     /// compiler.
969     fn run(self, builder: &Builder<'_>) -> Compiler {
970         let target_compiler = self.target_compiler;
971
972         if target_compiler.stage == 0 {
973             assert_eq!(builder.config.build, target_compiler.host,
974                 "Cannot obtain compiler for non-native build triple at stage 0");
975             // The stage 0 compiler for the build triple is always pre-built.
976             return target_compiler;
977         }
978
979         // Get the compiler that we'll use to bootstrap ourselves.
980         //
981         // Note that this is where the recursive nature of the bootstrap
982         // happens, as this will request the previous stage's compiler on
983         // downwards to stage 0.
984         //
985         // Also note that we're building a compiler for the host platform. We
986         // only assume that we can run `build` artifacts, which means that to
987         // produce some other architecture compiler we need to start from
988         // `build` to get there.
989         //
990         // FIXME: Perhaps we should download those libraries?
991         //        It would make builds faster...
992         //
993         // FIXME: It may be faster if we build just a stage 1 compiler and then
994         //        use that to bootstrap this compiler forward.
995         let build_compiler =
996             builder.compiler(target_compiler.stage - 1, builder.config.build);
997
998         // Build the libraries for this compiler to link to (i.e., the libraries
999         // it uses at runtime). NOTE: Crates the target compiler compiles don't
1000         // link to these. (FIXME: Is that correct? It seems to be correct most
1001         // of the time but I think we do link to these for stage2/bin compilers
1002         // when not performing a full bootstrap).
1003         builder.ensure(Rustc {
1004             compiler: build_compiler,
1005             target: target_compiler.host,
1006         });
1007         for &backend in builder.config.rust_codegen_backends.iter() {
1008             builder.ensure(CodegenBackend {
1009                 compiler: build_compiler,
1010                 target: target_compiler.host,
1011                 backend,
1012             });
1013         }
1014
1015         let lld_install = if builder.config.lld_enabled {
1016             Some(builder.ensure(native::Lld {
1017                 target: target_compiler.host,
1018             }))
1019         } else {
1020             None
1021         };
1022
1023         let stage = target_compiler.stage;
1024         let host = target_compiler.host;
1025         builder.info(&format!("Assembling stage{} compiler ({})", stage, host));
1026
1027         // Link in all dylibs to the libdir
1028         let sysroot = builder.sysroot(target_compiler);
1029         let rustc_libdir = builder.rustc_libdir(target_compiler);
1030         t!(fs::create_dir_all(&rustc_libdir));
1031         let src_libdir = builder.sysroot_libdir(build_compiler, host);
1032         for f in builder.read_dir(&src_libdir) {
1033             let filename = f.file_name().into_string().unwrap();
1034             if is_dylib(&filename) {
1035                 builder.copy(&f.path(), &rustc_libdir.join(&filename));
1036             }
1037         }
1038
1039         copy_codegen_backends_to_sysroot(builder,
1040                                          build_compiler,
1041                                          target_compiler);
1042         if let Some(lld_install) = lld_install {
1043             copy_lld_to_sysroot(builder, target_compiler, &lld_install);
1044         }
1045
1046         dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot);
1047
1048         // Link the compiler binary itself into place
1049         let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
1050         let rustc = out_dir.join(exe("rustc_binary", &*host));
1051         let bindir = sysroot.join("bin");
1052         t!(fs::create_dir_all(&bindir));
1053         let compiler = builder.rustc(target_compiler);
1054         let _ = fs::remove_file(&compiler);
1055         builder.copy(&rustc, &compiler);
1056
1057         target_compiler
1058     }
1059 }
1060
1061 /// Link some files into a rustc sysroot.
1062 ///
1063 /// For a particular stage this will link the file listed in `stamp` into the
1064 /// `sysroot_dst` provided.
1065 pub fn add_to_sysroot(
1066     builder: &Builder<'_>,
1067     sysroot_dst: &Path,
1068     sysroot_host_dst: &Path,
1069     stamp: &Path
1070 ) {
1071     t!(fs::create_dir_all(&sysroot_dst));
1072     t!(fs::create_dir_all(&sysroot_host_dst));
1073     for (path, host) in builder.read_stamp_file(stamp) {
1074         if host {
1075             builder.copy(&path, &sysroot_host_dst.join(path.file_name().unwrap()));
1076         } else {
1077             builder.copy(&path, &sysroot_dst.join(path.file_name().unwrap()));
1078         }
1079     }
1080 }
1081
1082 pub fn run_cargo(builder: &Builder<'_>,
1083                  cargo: &mut Command,
1084                  tail_args: Vec<String>,
1085                  stamp: &Path,
1086                  is_check: bool)
1087     -> Vec<PathBuf>
1088 {
1089     if builder.config.dry_run {
1090         return Vec::new();
1091     }
1092
1093     // `target_root_dir` looks like $dir/$target/release
1094     let target_root_dir = stamp.parent().unwrap();
1095     // `target_deps_dir` looks like $dir/$target/release/deps
1096     let target_deps_dir = target_root_dir.join("deps");
1097     // `host_root_dir` looks like $dir/release
1098     let host_root_dir = target_root_dir.parent().unwrap() // chop off `release`
1099                                        .parent().unwrap() // chop off `$target`
1100                                        .join(target_root_dir.file_name().unwrap());
1101
1102     // Spawn Cargo slurping up its JSON output. We'll start building up the
1103     // `deps` array of all files it generated along with a `toplevel` array of
1104     // files we need to probe for later.
1105     let mut deps = Vec::new();
1106     let mut toplevel = Vec::new();
1107     let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| {
1108         let (filenames, crate_types) = match msg {
1109             CargoMessage::CompilerArtifact {
1110                 filenames,
1111                 target: CargoTarget {
1112                     crate_types,
1113                 },
1114                 ..
1115             } => (filenames, crate_types),
1116             CargoMessage::CompilerMessage { message } => {
1117                 eprintln!("{}", message.rendered);
1118                 return;
1119             }
1120             _ => return,
1121         };
1122         for filename in filenames {
1123             // Skip files like executables
1124             if !filename.ends_with(".rlib") &&
1125                !filename.ends_with(".lib") &&
1126                !is_dylib(&filename) &&
1127                !(is_check && filename.ends_with(".rmeta")) {
1128                 continue;
1129             }
1130
1131             let filename = Path::new(&*filename);
1132
1133             // If this was an output file in the "host dir" we don't actually
1134             // worry about it, it's not relevant for us
1135             if filename.starts_with(&host_root_dir) {
1136                 // Unless it's a proc macro used in the compiler
1137                 if crate_types.iter().any(|t| t == "proc-macro") {
1138                     deps.push((filename.to_path_buf(), true));
1139                 }
1140                 continue;
1141             }
1142
1143             // If this was output in the `deps` dir then this is a precise file
1144             // name (hash included) so we start tracking it.
1145             if filename.starts_with(&target_deps_dir) {
1146                 deps.push((filename.to_path_buf(), false));
1147                 continue;
1148             }
1149
1150             // Otherwise this was a "top level artifact" which right now doesn't
1151             // have a hash in the name, but there's a version of this file in
1152             // the `deps` folder which *does* have a hash in the name. That's
1153             // the one we'll want to we'll probe for it later.
1154             //
1155             // We do not use `Path::file_stem` or `Path::extension` here,
1156             // because some generated files may have multiple extensions e.g.
1157             // `std-<hash>.dll.lib` on Windows. The aforementioned methods only
1158             // split the file name by the last extension (`.lib`) while we need
1159             // to split by all extensions (`.dll.lib`).
1160             let expected_len = t!(filename.metadata()).len();
1161             let filename = filename.file_name().unwrap().to_str().unwrap();
1162             let mut parts = filename.splitn(2, '.');
1163             let file_stem = parts.next().unwrap().to_owned();
1164             let extension = parts.next().unwrap().to_owned();
1165
1166             toplevel.push((file_stem, extension, expected_len));
1167         }
1168     });
1169
1170     if !ok {
1171         exit(1);
1172     }
1173
1174     // Ok now we need to actually find all the files listed in `toplevel`. We've
1175     // got a list of prefix/extensions and we basically just need to find the
1176     // most recent file in the `deps` folder corresponding to each one.
1177     let contents = t!(target_deps_dir.read_dir())
1178         .map(|e| t!(e))
1179         .map(|e| (e.path(), e.file_name().into_string().unwrap(), t!(e.metadata())))
1180         .collect::<Vec<_>>();
1181     for (prefix, extension, expected_len) in toplevel {
1182         let candidates = contents.iter().filter(|&&(_, ref filename, ref meta)| {
1183             filename.starts_with(&prefix[..]) &&
1184                 filename[prefix.len()..].starts_with("-") &&
1185                 filename.ends_with(&extension[..]) &&
1186                 meta.len() == expected_len
1187         });
1188         let max = candidates.max_by_key(|&&(_, _, ref metadata)| {
1189             FileTime::from_last_modification_time(metadata)
1190         });
1191         let path_to_add = match max {
1192             Some(triple) => triple.0.to_str().unwrap(),
1193             None => panic!("no output generated for {:?} {:?}", prefix, extension),
1194         };
1195         if is_dylib(path_to_add) {
1196             let candidate = format!("{}.lib", path_to_add);
1197             let candidate = PathBuf::from(candidate);
1198             if candidate.exists() {
1199                 deps.push((candidate, false));
1200             }
1201         }
1202         deps.push((path_to_add.into(), false));
1203     }
1204
1205     // Now we want to update the contents of the stamp file, if necessary. First
1206     // we read off the previous contents along with its mtime. If our new
1207     // contents (the list of files to copy) is different or if any dep's mtime
1208     // is newer then we rewrite the stamp file.
1209     deps.sort();
1210     let stamp_contents = fs::read(stamp);
1211     let stamp_mtime = mtime(&stamp);
1212     let mut new_contents = Vec::new();
1213     let mut max = None;
1214     let mut max_path = None;
1215     for (dep, proc_macro) in deps.iter() {
1216         let mtime = mtime(dep);
1217         if Some(mtime) > max {
1218             max = Some(mtime);
1219             max_path = Some(dep.clone());
1220         }
1221         new_contents.extend(if *proc_macro { b"h" } else { b"t" });
1222         new_contents.extend(dep.to_str().unwrap().as_bytes());
1223         new_contents.extend(b"\0");
1224     }
1225     let max = max.unwrap();
1226     let max_path = max_path.unwrap();
1227     let contents_equal = stamp_contents
1228         .map(|contents| contents == new_contents)
1229         .unwrap_or_default();
1230     if contents_equal && max <= stamp_mtime {
1231         builder.verbose(&format!("not updating {:?}; contents equal and {:?} <= {:?}",
1232                 stamp, max, stamp_mtime));
1233         return deps.into_iter().map(|(d, _)| d).collect()
1234     }
1235     if max > stamp_mtime {
1236         builder.verbose(&format!("updating {:?} as {:?} changed", stamp, max_path));
1237     } else {
1238         builder.verbose(&format!("updating {:?} as deps changed", stamp));
1239     }
1240     t!(fs::write(&stamp, &new_contents));
1241     deps.into_iter().map(|(d, _)| d).collect()
1242 }
1243
1244 pub fn stream_cargo(
1245     builder: &Builder<'_>,
1246     cargo: &mut Command,
1247     tail_args: Vec<String>,
1248     cb: &mut dyn FnMut(CargoMessage<'_>),
1249 ) -> bool {
1250     if builder.config.dry_run {
1251         return true;
1252     }
1253     // Instruct Cargo to give us json messages on stdout, critically leaving
1254     // stderr as piped so we can get those pretty colors.
1255     cargo.arg("--message-format").arg("json")
1256          .stdout(Stdio::piped());
1257
1258     for arg in tail_args {
1259         cargo.arg(arg);
1260     }
1261
1262     builder.verbose(&format!("running: {:?}", cargo));
1263     let mut child = match cargo.spawn() {
1264         Ok(child) => child,
1265         Err(e) => panic!("failed to execute command: {:?}\nerror: {}", cargo, e),
1266     };
1267
1268     // Spawn Cargo slurping up its JSON output. We'll start building up the
1269     // `deps` array of all files it generated along with a `toplevel` array of
1270     // files we need to probe for later.
1271     let stdout = BufReader::new(child.stdout.take().unwrap());
1272     for line in stdout.lines() {
1273         let line = t!(line);
1274         match serde_json::from_str::<CargoMessage<'_>>(&line) {
1275             Ok(msg) => cb(msg),
1276             // If this was informational, just print it out and continue
1277             Err(_) => println!("{}", line)
1278         }
1279     }
1280
1281     // Make sure Cargo actually succeeded after we read all of its stdout.
1282     let status = t!(child.wait());
1283     if !status.success() {
1284         eprintln!("command did not execute successfully: {:?}\n\
1285                   expected success, got: {}",
1286                  cargo,
1287                  status);
1288     }
1289     status.success()
1290 }
1291
1292 #[derive(Deserialize)]
1293 pub struct CargoTarget<'a> {
1294     crate_types: Vec<Cow<'a, str>>,
1295 }
1296
1297 #[derive(Deserialize)]
1298 #[serde(tag = "reason", rename_all = "kebab-case")]
1299 pub enum CargoMessage<'a> {
1300     CompilerArtifact {
1301         package_id: Cow<'a, str>,
1302         features: Vec<Cow<'a, str>>,
1303         filenames: Vec<Cow<'a, str>>,
1304         target: CargoTarget<'a>,
1305     },
1306     BuildScriptExecuted {
1307         package_id: Cow<'a, str>,
1308     },
1309     CompilerMessage {
1310         message: ClippyMessage<'a>
1311     }
1312 }
1313
1314 #[derive(Deserialize)]
1315 pub struct ClippyMessage<'a> {
1316     rendered: Cow<'a, str>,
1317 }