Skip to content

Commit 8b5dc38

Browse files
steffengySteffen Butzer
authored and
Steffen Butzer
committed
windows: detect architecture on website, update to matching arch (rust-lang#1353)
Updates on windows will now switch over to host appropriate versions, ensuring the best user experience (e.g. x86_64 builds on x64). The website can distinguish between Win64/Win32 builds now and a new platform can be introduced more easily.
1 parent f387275 commit 8b5dc38

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

src/rustup-cli/self_update.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,17 @@ pub fn prepare_update() -> Result<Option<PathBuf>> {
14481448
}
14491449

14501450
// Get build triple
1451-
let triple = dist::TargetTriple::from_build();
1451+
let triple = match dist::TargetTriple::from_build() {
1452+
// For windows x86 builds seem slow when used with windows defender.
1453+
// The website defaulted to i686-windows-gnu builds for a long time.
1454+
// This ensures that we update to a version thats appropriate for users
1455+
// and also works around if the website messed up the detection.
1456+
// If someone really wants to use another version, he still can enforce
1457+
// that using the environment variable RUSTUP_OVERRIDE_HOST_TRIPLE.
1458+
#[cfg(windows)]
1459+
build_triple => dist::TargetTriple::from_host().unwrap_or(build_triple),
1460+
build_triple => build_triple,
1461+
};
14521462

14531463
let update_root = env::var("RUSTUP_UPDATE_ROOT")
14541464
.unwrap_or(String::from(UPDATE_ROOT));

www/index.html

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@
2828
<pre>curl https://sh.rustup.rs -sSf | sh</pre>
2929
</div>
3030

31-
<div id="platform-instructions-win" class="instructions" style="display: none;">
31+
<div id="platform-instructions-win32" class="instructions" style="display: none;">
3232
<p>
3333
Download and run
34-
<a href="https://win.rustup.rs">rustup&#x2011;init.exe</a>
34+
<a href="https://win.rustup.rs/i686">rustup&#x2011;init.exe</a>
35+
then follow the onscreen instructions.
36+
</p>
37+
</div>
38+
39+
<div id="platform-instructions-win64" class="instructions" style="display: none;">
40+
<p>
41+
Download and run
42+
<a href="https://win.rustup.rs/x86_64">rustup&#x2011;init.exe</a>
3543
then follow the onscreen instructions.
3644
</p>
3745
</div>

www/rustup.js

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
var platforms = ["default", "unknown", "win32", "win64", "unix"];
12
var platform_override = null;
23

34
function detect_platform() {
45
"use strict";
56

6-
if (platform_override) {
7-
return platform_override;
7+
if (platform_override !== null) {
8+
return platforms[platform_override];
89
}
910

1011
var os = "unknown";
@@ -20,15 +21,18 @@ function detect_platform() {
2021
if (navigator.platform == "Linux mips") {os = "unix";}
2122
if (navigator.platform == "Linux mips64") {os = "unix";}
2223
if (navigator.platform == "Mac") {os = "unix";}
23-
if (navigator.platform == "Win32") {os = "win";}
24+
if (navigator.platform == "Win32") {os = "win32";}
25+
if (navigator.platform == "Win64" ||
26+
navigator.userAgent.indexOf("WOW64") != -1 ||
27+
navigator.userAgent.indexOf("Win64") != -1) { os = "win64"; }
2428
if (navigator.platform == "FreeBSD x86_64") {os = "unix";}
2529
if (navigator.platform == "FreeBSD amd64") {os = "unix";}
2630
if (navigator.platform == "NetBSD x86_64") {os = "unix";}
2731
if (navigator.platform == "NetBSD amd64") {os = "unix";}
2832

2933
// I wish I knew by now, but I don't. Try harder.
3034
if (os == "unknown") {
31-
if (navigator.appVersion.indexOf("Win")!=-1) {os = "win";}
35+
if (navigator.appVersion.indexOf("Win")!=-1) {os = "win32";}
3236
if (navigator.appVersion.indexOf("Mac")!=-1) {os = "unix";}
3337
// rust-www/#692 - FreeBSD epiphany!
3438
if (navigator.appVersion.indexOf("FreeBSD")!=-1) {os = "unix";}
@@ -42,39 +46,17 @@ function adjust_for_platform() {
4246

4347
var platform = detect_platform();
4448

45-
var unix_div = document.getElementById("platform-instructions-unix");
46-
var win_div = document.getElementById("platform-instructions-win");
47-
var unknown_div = document.getElementById("platform-instructions-unknown");
48-
var default_div = document.getElementById("platform-instructions-default");
49-
50-
unix_div.style.display = "none";
51-
win_div.style.display = "none";
52-
unknown_div.style.display = "none";
53-
default_div.style.display = "none";
54-
55-
if (platform == "unix") {
56-
unix_div.style.display = "block";
57-
} else if (platform == "win") {
58-
win_div.style.display = "block";
59-
} else if (platform == "unknown") {
60-
unknown_div.style.display = "block";
61-
} else {
62-
default_div.style.display = "block";
63-
}
49+
platforms.forEach(function (platform_elem) {
50+
var platform_div = document.getElementById("platform-instructions-" + platform_elem);
51+
platform_div.style.display = "none";
52+
if (platform == platform_elem) {
53+
platform_div.style.display = "block";
54+
}
55+
});
6456
}
6557

6658
function cycle_platform() {
67-
if (platform_override == null) {
68-
platform_override = "default";
69-
} else if (platform_override == "default") {
70-
platform_override = "unknown";
71-
} else if (platform_override == "unknown") {
72-
platform_override = "win";
73-
} else if (platform_override == "win") {
74-
platform_override = "unix";
75-
} else if (platform_override == "unix") {
76-
platform_override = "default";
77-
}
59+
platform_override = (platform_override + 1) % platforms.length;
7860
adjust_for_platform();
7961
}
8062

0 commit comments

Comments
 (0)