Skip to content

Fix and re-enable MSI build #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ environment:
- TARGET: x86_64-pc-windows-msvc
ALLOW_PR: 1
- TARGET: i686-pc-windows-msvc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed now that BUILD_MSI is enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSI version is nowhere near finished. I want to enable it on CI just so it won't break. Maybe it would make sense to also set ALLOW_PR: 1 for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, that makes sense and no worries! My only worry is that this'll conflict with the other i686 builder for the dist artifacts being produced. Enabling the MSI installer just builds more artifacts, right? It shouldn't change the existing binaries?

(if so we can probably just gate on the msi build)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No artifacts are being produced for MSI currently, see https://github.com/rust-lang-nursery/rustup.rs/blob/ac5bffad7ba126b2313692c3dfce83ec91cb7fea/ci/prepare-deploy-appveyor.ps1#L9-L12

Changing that situation was part of #661, but I didn't include it here. Will do in another PR.

# 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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/rustup-win-installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
11 changes: 11 additions & 0 deletions src/rustup-win-installer/README.md
Original file line number Diff line number Diff line change
@@ -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`.
35 changes: 30 additions & 5 deletions src/rustup-win-installer/build.rs
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 6 additions & 1 deletion src/rustup-win-installer/msi/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
2 changes: 1 addition & 1 deletion src/rustup-win-installer/msi/rustup.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!-- TODO: Change paths and names accordingly -->
<?define TargetPath="..\..\..\target\$(var.TARGET)\release"?>
<?define RustupCustomActionDll="$(var.TargetPath)\deps\rustup_msi.dll"?>
<?define RustupCustomActionDll="$(var.TargetPath)\rustup_msi.dll"?>
<?define RustupExe="$(var.TargetPath)\rustup-init.exe"?>

<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">
Expand Down
2 changes: 1 addition & 1 deletion src/rustup-win-installer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down