Skip to content

Commit b7fe716

Browse files
committed
[rust] If $TMPDIR is unset, use $HOME/.tmp instead
This patch is needed because in sb2 the temp files written to /tmp by rustc are no longer available when the linker tries to use them. Work around the issue by setting $TMPDIR to $HOME/.tmp instead. If $TMPDIR is already set, that value is used as expected.
1 parent 4decb8a commit b7fe716

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

0009-Relocate-unset-tmp.patch

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
2+
index dd9d277fb..160e472cf 100644
3+
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
4+
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
5+
@@ -48,7 +48,7 @@ use std::ffi::OsString;
6+
use std::fs::{read, File, OpenOptions};
7+
use std::io::{BufWriter, Write};
8+
use std::ops::Deref;
9+
-use std::path::{Path, PathBuf};
10+
+use std::path::{MAIN_SEPARATOR, Path, PathBuf};
11+
use std::process::{ExitStatus, Output, Stdio};
12+
use std::{env, fmt, fs, io, mem, str};
13+
14+
@@ -95,11 +95,24 @@ pub fn link_binary<'a>(
15+
});
16+
17+
if outputs.outputs.should_link() {
18+
+ let mut clear_tmp = false;
19+
+ if env::var_os("TMPDIR").is_none() && env::var_os("HOME").is_some() {
20+
+ let home_tmp = env::var_os("HOME").unwrap();
21+
+ let home_tmp = format!("{}{}{}", home_tmp.to_string_lossy(), MAIN_SEPARATOR, ".tmp");
22+
+ env::set_var("TMPDIR", &home_tmp);
23+
+ if !Path::new(&home_tmp).exists() {
24+
+ let _ = fs::create_dir_all(home_tmp);
25+
+ }
26+
+ clear_tmp = true;
27+
+ }
28+
let tmpdir = TempFileBuilder::new()
29+
.prefix("rustc")
30+
.tempdir()
31+
.unwrap_or_else(|error| sess.emit_fatal(errors::CreateTempDir { error }));
32+
let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps);
33+
+ if clear_tmp {
34+
+ env::remove_var("TMP");
35+
+ }
36+
let output = out_filename(
37+
sess,
38+
crate_type,

rust.spec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Patch5: 0005-Provide-ENV-controls-to-bypass-some-sb2-calls-betwee.patch
7777
Patch6: 0006-Scratchbox2-needs-to-be-able-to-tell-cargo-the-defau.patch
7878
Patch7: 0007-Disable-aarch64-outline-atomics-for-now.patch
7979
Patch8: 0008-Revert-Use-statx-s-64-bit-times-on-32-bit-linux-gnu.patch
80+
Patch9: 0009-Relocate-unset-tmp.patch
8081
# This is the real rustc spec - the stub one appears near the end.
8182
%ifarch %ix86
8283

0 commit comments

Comments
 (0)