Skip to content
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

Embed manifest resource using MSVC toolchain, to avoid installer heuristics. #16

Merged
merged 1 commit into from
Nov 23, 2016
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
23 changes: 20 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ use std::path::Path;
use std::env;

fn main() {
if cfg!(target_os = "windows") && cfg!(target_env = "gnu") {
let out_dir = env::var("OUT_DIR").unwrap();
if cfg!(not(target_os = "windows")) {
return;
}

let out_dir = env::var("OUT_DIR").unwrap();

if cfg!(target_env = "gnu") {
Command::new("windres")
.args(&["--input", "cargo-install-update-manifest.rc", "--output-format=coff", "--output"])
.arg(&format!("{}/cargo-install-update-manifest.res", out_dir))
Expand All @@ -17,7 +21,20 @@ fn main() {
.current_dir(&Path::new(&out_dir))
.status()
.unwrap();
}

if cfg!(target_env = "msvc") {
// We'll create a `.res` file here, but name it as `.lib`,
// so that it can be found and linked correctly.
// Yes, `.res` may be linked directly, like `.lib` and `.o`.
Copy link
Owner

Choose a reason for hiding this comment

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

Oh god why

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why, but I know it works:)

Copy link
Owner

Choose a reason for hiding this comment

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

msvc.txt

// See `#[link(name="cargo-install-update-manifest")]` in main.rs.
let out_res = format!("{}\\cargo-install-update-manifest.lib", out_dir);

println!("cargo:rustc-link-search=native={}", out_dir);
Command::new("rc")
.args(&["/fo", &out_res, "cargo-install-update-manifest.rc"])
.status()
.unwrap();
}

println!("cargo:rustc-link-search=native={}", out_dir);
}
4 changes: 2 additions & 2 deletions cargo-install-update-manifest.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#include "winuser.h"
1 RT_MANIFEST cargo-install-update.exe.manifest
#define RT_MANIFEST 24
1 RT_MANIFEST "cargo-install-update.exe.manifest"