Skip to content

Commit c4e7616

Browse files
committed
Auto merge of #1211 - Boddlnagg:msi-improvements, r=alexcrichton
Fix and re-enable MSI build This supersedes #661, though it does not enable deployment yet.
2 parents ac5bffa + eaed698 commit c4e7616

8 files changed

Lines changed: 61 additions & 20 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

appveyor.yml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ environment:
55
- TARGET: x86_64-pc-windows-msvc
66
ALLOW_PR: 1
77
- TARGET: i686-pc-windows-msvc
8-
# FIXME
9-
#- TARGET: i686-pc-windows-msvc
10-
# BUILD_MSI: 1
8+
- TARGET: i686-pc-windows-msvc
9+
BUILD_MSI: 1
1110
- TARGET: i686-pc-windows-gnu
1211
MINGW_DIR: mingw32
1312
- TARGET: x86_64-pc-windows-gnu
@@ -75,15 +74,8 @@ test_script:
7574
- cargo build --release --target %TARGET% %FEATURES%
7675
- cargo test --release -p rustup-dist --target %TARGET%
7776
- cargo test --release --target %TARGET% %FEATURES%
78-
- ps: |
79-
if($env:BUILD_MSI) {
80-
cd src\rustup-win-installer
81-
cargo build --release --target $env:TARGET
82-
cd msi
83-
.\build.ps1 -Target $env:TARGET
84-
cd ..\..\..
85-
if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
86-
}
77+
- if defined BUILD_MSI pushd src\rustup-win-installer && cargo build --release --target %TARGET% & popd
78+
- if defined BUILD_MSI pushd src\rustup-win-installer\msi && powershell .\build.ps1 -Target %TARGET% & popd
8779

8880
notifications:
8981
- provider: Webhook

src/rustup-win-installer/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ build = "build.rs"
88
name = "rustup_msi"
99
crate-type = ["cdylib"]
1010

11+
[features]
12+
# Prevents confusion and reduces build time (`rustup` will be built twice otherwise)
13+
default = ["rustup/msi-installed"]
14+
1115
[dependencies]
1216
winapi = "0.2"
1317
rustup = { path = "../../", version = "1.1.0" }
18+
19+
[build-dependencies]
20+
gcc = "0.3"

src/rustup-win-installer/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# How to build
2+
3+
Important: For all `cargo build` invocations, set `--target` (even if the target is the same as the host architecture), because that affects the output directory. Pass the same target also via `-Target` to `build.ps1` in step 3.
4+
5+
## Steps
6+
7+
1) Build the main project with the `--features "msi-installed"` flag, resulting in `rustup-init.exe`
8+
2) Build the CustomAction DLL in `src/rustup-win-installer` using `cargo build`
9+
3) Build the actual installer in `src/rustup-win-installer/msi` using `build.ps1`
10+
11+
The resulting installer will be in `src/rustup-win-installer/msi/target`.

src/rustup-win-installer/build.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1+
extern crate gcc;
2+
13
use std::env;
4+
use gcc::windows_registry::{self, VsVers};
25

36
fn main() {
4-
println!("cargo:rustc-link-lib=static=wcautil");
5-
println!("cargo:rustc-link-lib=static=dutil");
67
println!("cargo:rustc-link-lib=dylib=msi");
78
println!("cargo:rustc-link-lib=dylib=user32");
89
println!("cargo:rustc-link-lib=dylib=mincore");
910

10-
let wix_path = env::var("WIX").unwrap();
11-
// x86 target is hard-coded because we only build an x86 installer (works just fine on x64)
12-
println!("cargo:rustc-link-search=native={}SDK\\VS2015\\lib\\x86", wix_path);
11+
// Part of WIX SDK
12+
println!("cargo:rustc-link-lib=static=wcautil");
13+
println!("cargo:rustc-link-lib=static=dutil");
14+
15+
let wix_path = env::var("WIX").expect("WIX must be installed, and 'WIX' environment variable must be set");
16+
17+
// For the correct WIX library path, we need to know which VS version we are using.
18+
// We use the `gcc` crate's functionality to do this, which should always match what rustc is doing.
19+
let vs_version = windows_registry::find_vs_version().expect("Cannot find VS version");
20+
let vs_version_string = match vs_version {
21+
VsVers::Vs14 => "VS2015",
22+
VsVers::Vs15 => "VS2017",
23+
VsVers::Vs12 => panic!("Unsupported VS version: Vs12"),
24+
_ => panic!("Unsupported VS version") // FIXME: should use {:?}, but `VsVers` does not yet implement `Debug`
25+
};
26+
27+
println!("cargo:warning=Using WIX libraries for VS version: {}", vs_version_string);
28+
29+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("cannot read CARGO_CFG_TARGET_ARCH in build script");
30+
let target_arch = match target_arch.as_str() {
31+
"x86" => "x86",
32+
"x86_64" => "x64",
33+
other => panic!("Target architecture {} not supported by WIX.", other)
34+
};
35+
36+
// Tell cargo about the WIX SDK path for `wcautil.lib` and `dutil.lib`
37+
println!("cargo:rustc-link-search=native={}SDK\\{}\\lib\\{}", wix_path, vs_version_string, target_arch);
1338
}

src/rustup-win-installer/msi/build.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ $env:CFG_VER_PATCH = $version[2]
1212
foreach($file in Get-ChildItem *.wxs) {
1313
$in = $file.Name
1414
$out = $($file.Name.Replace(".wxs",".wixobj"))
15-
&"$($env:WIX)bin\candle.exe" -nologo -arch x86 "-dTARGET=$Target" -ext WixUIExtension -ext WixUtilExtension -out "target\$out" $in
15+
if ($Target -match "x86_64") {
16+
$target_arch = "x64"
17+
} else {
18+
$target_arch = "x86"
19+
}
20+
&"$($env:WIX)bin\candle.exe" -nologo -arch "$target_arch" "-dTARGET=$Target" -ext WixUIExtension -ext WixUtilExtension -out "target\$out" $in
1621
if ($LASTEXITCODE -ne 0) { exit 1 }
1722
}
1823

src/rustup-win-installer/msi/rustup.wxs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
33
<!-- TODO: Change paths and names accordingly -->
44
<?define TargetPath="..\..\..\target\$(var.TARGET)\release"?>
5-
<?define RustupCustomActionDll="$(var.TargetPath)\deps\rustup_msi.dll"?>
5+
<?define RustupCustomActionDll="$(var.TargetPath)\rustup_msi.dll"?>
66
<?define RustupExe="$(var.TargetPath)\rustup-init.exe"?>
77

88
<Product Id="*" Name="rustup" Language="1033" Version="$(env.CFG_VER_MAJOR).$(env.CFG_VER_MINOR).$(env.CFG_VER_PATCH).0" Manufacturer="The Rust Project Developers" UpgradeCode="09acbb1c-7123-44ac-b2a9-4a04b28ced11">

src/rustup-win-installer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const LOGMSG_STANDARD: i32 = 2;
1515

1616
// TODO: share this with self_update.rs
1717
static TOOLS: &'static [&'static str]
18-
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb"];
18+
= &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls"];
1919

2020
#[no_mangle]
2121
/// This is run as an `immediate` action early in the install sequence

0 commit comments

Comments
 (0)