aboutsummaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-11-14 02:04:39 -0700
committerMelody Horn <melody@boringcactus.com>2021-11-14 02:04:39 -0700
commitb0b7b736fa33be1e363d20c134793082e42e7047 (patch)
tree967cd10ceedc35642c480e16a4f9acb1a0f17448 /build.rs
parent2c422c2841f24be9a3fb65b1bf090bc847bae2b4 (diff)
downloadshit-wx-sys-b0b7b736fa33be1e363d20c134793082e42e7047.tar.gz
shit-wx-sys-b0b7b736fa33be1e363d20c134793082e42e7047.zip
holy shit did something just fucking workHEADcanon
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs101
1 files changed, 3 insertions, 98 deletions
diff --git a/build.rs b/build.rs
index adc18c6..381597f 100644
--- a/build.rs
+++ b/build.rs
@@ -1,59 +1,6 @@
use std::env;
-use std::ffi::{OsStr, OsString};
-use std::fs;
-use std::io;
-use std::path::{Path, PathBuf};
-use anyhow::{anyhow, ensure, Result};
-use url::Url;
-
-// there's probably a crate for this somewhere
-fn os_concat(a: impl AsRef<OsStr>, b: impl AsRef<OsStr>) -> OsString {
- let mut result = OsString::from(&a);
- result.push(b);
- result
-}
-
-fn out_dir() -> PathBuf {
- PathBuf::from(env::var_os("OUT_DIR").expect("no OUT_DIR found"))
-}
-
-fn download(url: &str) -> Result<PathBuf> {
- let url = Url::parse(url)?;
- let file_name = url
- .path_segments()
- .and_then(|x| x.last())
- .ok_or_else(|| anyhow!("Weird URL downloaded"))?;
- let out_path = out_dir().join(file_name);
- if !out_path.exists() {
- let mut body_reader = ureq::request_url("GET", &url).call()?.into_reader();
- let mut out_file = fs::File::create(&out_path)?;
- io::copy(&mut body_reader, &mut out_file)?;
- }
- Ok(out_path)
-}
-
-fn un7z(archive: PathBuf) -> Result<()> {
- // WARNING: This code is horrifying and also bad.
- // It should never be used by anyone.
- // TODO port the 7zip LZMA SDK to Rust
- use std::process::{Command, Stdio};
- let my_7z_exe = Path::new(r"C:\Program Files\7-Zip\7z.exe");
- ensure!(my_7z_exe.exists());
- let output_folder = archive
- .parent()
- .ok_or_else(|| anyhow!("archive with no parent"))?;
- let output_folder_arg = os_concat("-o", &output_folder);
- let extract_result = Command::new(my_7z_exe)
- .args(["x", "-aos"])
- .arg(output_folder_arg)
- .arg(&archive)
- .stdin(Stdio::null())
- .stdout(Stdio::null())
- .status()?;
- ensure!(extract_result.success());
- Ok(())
-}
+use anyhow::Result;
fn main() -> Result<()> {
println!("cargo:rerun-if-changed=build.rs");
@@ -65,49 +12,12 @@ fn main() -> Result<()> {
}
}
-/*
- <Choose>
- <When Condition="Exists('lib\vc14x_x64_dll\wxbase31$(wxSuffix).lib')">
- <PropertyGroup Label="UserMacros">
- <wxUsingVersionABICompat>1</wxUsingVersionABICompat>
- <wxUsingDll>1</wxUsingDll>
- <wxLibOrDllDir>lib\vc14x_x64_dll</wxLibOrDllDir>
- </PropertyGroup>
- </When>
-
- <When Condition="Exists('lib\vc14x_x64_lib\wxbase31$(wxSuffix).lib')">
- <PropertyGroup Label="UserMacros">
- <wxUsingVersionABICompat>1</wxUsingVersionABICompat>
- <wxUsingLib>1</wxUsingLib>
- <wxLibOrDllDir>lib\vc14x_x64_lib</wxLibOrDllDir>
- </PropertyGroup>
- </When>
- </Choose>
-*/
-
fn build_x64_windows_msvc() -> Result<()> {
- let headers = download("https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxWidgets-3.1.5-headers.7z")?;
- un7z(headers)?;
-
- // TODO make sure VS2015+ is actually the right thing
- let libs = download("https://github.com/wxWidgets/wxWidgets/releases/download/v3.1.5/wxMSW-3.1.5_vc14x_x64_Dev.7z")?;
- un7z(libs)?;
-
- let out_dir = out_dir();
-
- // TODO consider actually parsing wxwidgets.props at build time instead of doing it manually
- // TODO find a static build instead bc fuck DLLs
- let libs_folder = out_dir.join("lib/vc14x_x64_dll");
- let debug = env::var("PROFILE")? == "release";
- let wx_suffix = if debug { "u" } else { "ud" };
-
- let mut include_dirs = vec![out_dir.join("include/msvc"), out_dir.join("include")];
- // TODO this is only in ResourceCompile in wxwidgets.props, is that bad
- include_dirs.push(libs_folder.join(format!("msw{}", wx_suffix)));
+ let wx = vcpkg::find_package("wxwidgets").unwrap();
cxx_build::bridge("src/lib.rs")
.file("src/wx-sys.cpp")
- .includes(include_dirs)
+ .includes(wx.include_paths)
.flag_if_supported("-Wno-invalid-token-paste")
.define("__WXMSW__", None)
.define("wxMSVC_VERSION_AUTO", None)
@@ -131,10 +41,5 @@ fn build_x64_windows_msvc() -> Result<()> {
// TODO dylib or static
println!("cargo:rustc-link-lib={}", lib);
}
- // TODO is "native=" the right thing there (or display() for that matter)
- println!("cargo:rustc-link-search=native={}", libs_folder.display());
-
- // TODO which libs do we actually want to link
- println!("cargo:rustc-link-lib=static=wxmsw31{}_core", wx_suffix);
Ok(())
}