diff --git a/Cargo.lock b/Cargo.lock index 9a3ad372ba..a1e06a14ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,7 @@ name = "rustup-win-installer" version = "1.5.0" dependencies = [ + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", "rustup 1.5.0", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/appveyor.yml b/appveyor.yml index f83d91eee2..11e1ac972d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,9 +5,8 @@ environment: - TARGET: x86_64-pc-windows-msvc ALLOW_PR: 1 - TARGET: i686-pc-windows-msvc - # FIXME - #- TARGET: i686-pc-windows-msvc - # BUILD_MSI: 1 + - TARGET: i686-pc-windows-msvc + BUILD_MSI: 1 - TARGET: i686-pc-windows-gnu MINGW_DIR: mingw32 - TARGET: x86_64-pc-windows-gnu @@ -72,15 +71,8 @@ test_script: - cargo build --release --target %TARGET% %FEATURES% - cargo test --release -p rustup-dist --target %TARGET% - cargo test --release --target %TARGET% %FEATURES% - - ps: | - if($env:BUILD_MSI) { - cd src\rustup-win-installer - cargo build --release --target $env:TARGET - cd msi - .\build.ps1 -Target $env:TARGET - cd ..\..\.. - if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) } - } + - if defined BUILD_MSI pushd src\rustup-win-installer && cargo build --release --target %TARGET% & popd + - if defined BUILD_MSI pushd src\rustup-win-installer\msi && powershell .\build.ps1 -Target %TARGET% & popd notifications: - provider: Webhook diff --git a/src/rustup-win-installer/Cargo.toml b/src/rustup-win-installer/Cargo.toml index 2dd76807a8..415a5341b0 100644 --- a/src/rustup-win-installer/Cargo.toml +++ b/src/rustup-win-installer/Cargo.toml @@ -8,6 +8,13 @@ build = "build.rs" name = "rustup_msi" crate-type = ["cdylib"] +[features] +# Prevents confusion and reduces build time (`rustup` will be built twice otherwise) +default = ["rustup/msi-installed"] + [dependencies] winapi = "0.2" rustup = { path = "../../", version = "1.1.0" } + +[build-dependencies] +gcc = "0.3" diff --git a/src/rustup-win-installer/README.md b/src/rustup-win-installer/README.md new file mode 100644 index 0000000000..535f58fff5 --- /dev/null +++ b/src/rustup-win-installer/README.md @@ -0,0 +1,11 @@ +# How to build + +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. + +## Steps + +1) Build the main project with the `--features "msi-installed"` flag, resulting in `rustup-init.exe` +2) Build the CustomAction DLL in `src/rustup-win-installer` using `cargo build` +3) Build the actual installer in `src/rustup-win-installer/msi` using `build.ps1` + +The resulting installer will be in `src/rustup-win-installer/msi/target`. \ No newline at end of file diff --git a/src/rustup-win-installer/build.rs b/src/rustup-win-installer/build.rs index 57da43c97b..eb1bafcf1a 100644 --- a/src/rustup-win-installer/build.rs +++ b/src/rustup-win-installer/build.rs @@ -1,13 +1,38 @@ +extern crate gcc; + use std::env; +use gcc::windows_registry::{self, VsVers}; fn main() { - println!("cargo:rustc-link-lib=static=wcautil"); - println!("cargo:rustc-link-lib=static=dutil"); println!("cargo:rustc-link-lib=dylib=msi"); println!("cargo:rustc-link-lib=dylib=user32"); println!("cargo:rustc-link-lib=dylib=mincore"); - let wix_path = env::var("WIX").unwrap(); - // x86 target is hard-coded because we only build an x86 installer (works just fine on x64) - println!("cargo:rustc-link-search=native={}SDK\\VS2015\\lib\\x86", wix_path); + // Part of WIX SDK + println!("cargo:rustc-link-lib=static=wcautil"); + println!("cargo:rustc-link-lib=static=dutil"); + + let wix_path = env::var("WIX").expect("WIX must be installed, and 'WIX' environment variable must be set"); + + // For the correct WIX library path, we need to know which VS version we are using. + // We use the `gcc` crate's functionality to do this, which should always match what rustc is doing. + let vs_version = windows_registry::find_vs_version().expect("Cannot find VS version"); + let vs_version_string = match vs_version { + VsVers::Vs14 => "VS2015", + VsVers::Vs15 => "VS2017", + VsVers::Vs12 => panic!("Unsupported VS version: Vs12"), + _ => panic!("Unsupported VS version") // FIXME: should use {:?}, but `VsVers` does not yet implement `Debug` + }; + + println!("cargo:warning=Using WIX libraries for VS version: {}", vs_version_string); + + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("cannot read CARGO_CFG_TARGET_ARCH in build script"); + let target_arch = match target_arch.as_str() { + "x86" => "x86", + "x86_64" => "x64", + other => panic!("Target architecture {} not supported by WIX.", other) + }; + + // Tell cargo about the WIX SDK path for `wcautil.lib` and `dutil.lib` + println!("cargo:rustc-link-search=native={}SDK\\{}\\lib\\{}", wix_path, vs_version_string, target_arch); } \ No newline at end of file diff --git a/src/rustup-win-installer/msi/build.ps1 b/src/rustup-win-installer/msi/build.ps1 index bf45d1fb17..5a57874285 100644 --- a/src/rustup-win-installer/msi/build.ps1 +++ b/src/rustup-win-installer/msi/build.ps1 @@ -12,7 +12,12 @@ $env:CFG_VER_PATCH = $version[2] foreach($file in Get-ChildItem *.wxs) { $in = $file.Name $out = $($file.Name.Replace(".wxs",".wixobj")) - &"$($env:WIX)bin\candle.exe" -nologo -arch x86 "-dTARGET=$Target" -ext WixUIExtension -ext WixUtilExtension -out "target\$out" $in + if ($Target -match "x86_64") { + $target_arch = "x64" + } else { + $target_arch = "x86" + } + &"$($env:WIX)bin\candle.exe" -nologo -arch "$target_arch" "-dTARGET=$Target" -ext WixUIExtension -ext WixUtilExtension -out "target\$out" $in if ($LASTEXITCODE -ne 0) { exit 1 } } diff --git a/src/rustup-win-installer/msi/rustup.wxs b/src/rustup-win-installer/msi/rustup.wxs index 32473d0df4..3d375f6f4e 100644 --- a/src/rustup-win-installer/msi/rustup.wxs +++ b/src/rustup-win-installer/msi/rustup.wxs @@ -2,7 +2,7 @@ - + diff --git a/src/rustup-win-installer/src/lib.rs b/src/rustup-win-installer/src/lib.rs index 2b5491c34e..2f2aea0da1 100644 --- a/src/rustup-win-installer/src/lib.rs +++ b/src/rustup-win-installer/src/lib.rs @@ -15,7 +15,7 @@ pub const LOGMSG_STANDARD: i32 = 2; // TODO: share this with self_update.rs static TOOLS: &'static [&'static str] - = &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb"]; + = &["rustc", "rustdoc", "cargo", "rust-lldb", "rust-gdb", "rls"]; #[no_mangle] /// This is run as an `immediate` action early in the install sequence