diff --git a/edgelet/Cargo.lock b/edgelet/Cargo.lock index 113360388bc..f000c8c127a 100644 --- a/edgelet/Cargo.lock +++ b/edgelet/Cargo.lock @@ -798,8 +798,10 @@ dependencies = [ "tokio-signal 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version-compare 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "win-logger 0.1.0", "windows-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1874,6 +1876,11 @@ name = "vec_map" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "version-compare" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.3" @@ -1947,6 +1954,14 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winreg" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "workload" version = "0.1.0" @@ -2155,6 +2170,7 @@ dependencies = [ "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380" "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" +"checksum version-compare 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "78068add8bf1e4d37d13fa5867182fe4c03f8e525c831053733f83aaba942d37" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum widestring 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a212922ea58fbf5044f83663aa4fc6281ff890f1fd7546c0c3f52f5290831781" @@ -2165,5 +2181,6 @@ dependencies = [ "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb06499a3a4d44302791052df005d5232b927ed1a9658146d842165c4de7767" "checksum windows-service 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "51cb08429e18f787748343122610b09f50c79f8034627e57faacf37582a709ec" +"checksum winreg 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a27a759395c1195c4cc5cda607ef6f8f6498f64e78f7900f5de0a127a424704a" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum yaml-rust 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57ab38ee1a4a266ed033496cf9af1828d8d6e6c1cfa5f643a2809effcae4d628" diff --git a/edgelet/iotedged/Cargo.toml b/edgelet/iotedged/Cargo.toml index 65efee1b348..c75cf8ed687 100644 --- a/edgelet/iotedged/Cargo.toml +++ b/edgelet/iotedged/Cargo.toml @@ -43,4 +43,9 @@ win-logger = { path = "../win-logger" } [dev_dependencies] tempdir = "0.3.7" + edgelet-test-utils = { path = "../edgelet-test-utils" } + +[target.'cfg(windows)'.build-dependencies] +winreg = "0.5.1" +version-compare = "0.0.6" \ No newline at end of file diff --git a/edgelet/iotedged/build.rs b/edgelet/iotedged/build.rs index 31001e28cb3..9a8cdef133a 100644 --- a/edgelet/iotedged/build.rs +++ b/edgelet/iotedged/build.rs @@ -1,11 +1,87 @@ +// Copyright (c) Microsoft. All rights reserved. +#[cfg(windows)] +extern crate version_compare; +#[cfg(windows)] +extern crate winreg; + fn main() { #[cfg(windows)] - { - let current_dir = ::std::env::var("CARGO_MANIFEST_DIR").unwrap(); - println!( - "cargo:rustc-link-search=all={}\\src\\resources", - current_dir, - ); + windows::main() +} + +#[cfg(windows)] +mod windows { + use std::cmp::Ordering; + use std::env; + use std::fs; + use std::io::Result; + use std::path::{Path, PathBuf}; + use std::process::Command; + + use version_compare::comp_op::CompOp; + use version_compare::VersionCompare; + use winreg::enums::*; + use winreg::RegKey; + + pub fn main() { + // on windows we only support x64 at this time + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + if target_arch != "x86_64" { + panic!("Only x64 architecture is supported on Windows at this time."); + } + + let sdk_bin_root = get_sdk_bin_root().expect("Could not get Windows SDK root bin path"); + let mc_path = sdk_bin_root.join("mc.exe"); + let rc_path = sdk_bin_root.join("rc.exe"); + let out_dir = env::var("OUT_DIR").unwrap(); + + Command::new(mc_path.to_str().unwrap()) + .args(&[ + "-r", + &out_dir, + "-h", + &out_dir, + "src\\resources\\event_messages.mc", + ]) + .status() + .expect("Message compilation failed"); + + let rc_source_path = Path::new(&out_dir).join("event_messages.rc"); + Command::new(rc_path.to_str().unwrap()) + .args(&[rc_source_path.to_str().unwrap()]) + .status() + .expect("Resource compilation failed"); + + fs::rename( + Path::new(&out_dir).join("event_messages.res"), + Path::new(&out_dir).join("event_messages.res.lib"), + ).expect("Rename of event_messages.res failed"); + + println!("cargo:rustc-link-search=all={}", out_dir); println!("cargo:rustc-link-lib=event_messages.res"); } + + fn get_sdk_bin_root() -> Result { + let hklm = RegKey::predef(HKEY_LOCAL_MACHINE); + let installed_roots = + hklm.open_subkey("SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots")?; + let max_version = installed_roots + .enum_keys() + .map(|v| v.unwrap()) + .max_by(|v1, v2| comp_op_to_ordering(VersionCompare::compare(v1, v2).unwrap())) + .unwrap(); + + let kits_root: String = installed_roots.get_value("KitsRoot10").unwrap(); + let install_root = Path::new(&kits_root); + + Ok(install_root.join("bin").join(max_version).join("x64")) + } + + fn comp_op_to_ordering(op: CompOp) -> Ordering { + match op { + CompOp::Eq | CompOp::Le | CompOp::Ge => Ordering::Equal, + CompOp::Lt | CompOp::Ne => Ordering::Less, + CompOp::Gt => Ordering::Greater, + } + } } diff --git a/edgelet/iotedged/src/resources/MSG00001.bin b/edgelet/iotedged/src/resources/MSG00001.bin deleted file mode 100644 index 99fc3cb038d..00000000000 Binary files a/edgelet/iotedged/src/resources/MSG00001.bin and /dev/null differ diff --git a/edgelet/iotedged/src/resources/event_messages.rc b/edgelet/iotedged/src/resources/event_messages.rc deleted file mode 100644 index 0abcb0fa2c5..00000000000 --- a/edgelet/iotedged/src/resources/event_messages.rc +++ /dev/null @@ -1,2 +0,0 @@ -LANGUAGE 0x9,0x1 -1 11 "MSG00001.bin" diff --git a/edgelet/iotedged/src/resources/event_messages.res.lib b/edgelet/iotedged/src/resources/event_messages.res.lib deleted file mode 100644 index a6d89738440..00000000000 Binary files a/edgelet/iotedged/src/resources/event_messages.res.lib and /dev/null differ