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

WIP: build and run on windows #32

Merged
merged 7 commits into from
Apr 2, 2022
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
2 changes: 2 additions & 0 deletions example/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![windows_subsystem = "windows"]

use wx_base::*;
use wx;
use wx::*;
Expand Down
5 changes: 4 additions & 1 deletion gen_defs_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#![allow(non_upper_case_globals)]
#![allow(unused_parens)]

// FIXME: workaround for windows (LLP64)
#![allow(overflowing_literals)]

use std::os::raw::{c_int, c_long};

use crate::manual::*;
Expand All @@ -15,7 +18,7 @@
# place wxWidgets doxygen xml files in wxml/ dir and run this.
generated = set()
def main():
with open('src/defs.rs', 'w') as f:
with open('wx-base/src/defs.rs', 'w') as f:
print(PROLOGUE, file=f)
for file in xml_files_in('wxml/'):
tree = ET.parse(file)
Expand Down
3 changes: 3 additions & 0 deletions wx-base/src/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#![allow(non_upper_case_globals)]
#![allow(unused_parens)]

// FIXME: workaround for windows (LLP64)
#![allow(overflowing_literals)]

use std::os::raw::{c_int, c_long};

use crate::manual::*;
Expand Down
55 changes: 46 additions & 9 deletions wxrust-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::env;
use std::process::Command;

pub fn wx_config_cflags(cc_build: &mut cc::Build) -> &mut cc::Build {
// from `wx-config --cflags`
let cflags = wx_config(&["--cflags"]);
// ignore too many warnings with wx3.0
cc_build.flag("-Wno-deprecated-copy");
cc_build.flag("-Wno-ignored-qualifiers");
cc_build.flag("-Wno-unused-parameter");
cc_build.flag_if_supported("-Wno-deprecated-copy")
.flag_if_supported("-Wno-ignored-qualifiers")
.flag_if_supported("-Wno-unused-parameter");
for arg in cflags.split_whitespace() {
if arg.starts_with("-I") {
cc_build.include(&arg[2..]);
Expand All @@ -19,6 +20,9 @@ pub fn wx_config_cflags(cc_build: &mut cc::Build) -> &mut cc::Build {
panic!("unsupported argument '{}'. please file a bug.", arg)
}
}
if cfg!(windows) {
cc_build.flag("/EHsc");
}
cc_build
}

Expand All @@ -44,10 +48,43 @@ pub fn print_wx_config_libs_for_cargo() {
}
}

pub fn wx_config(args: &[&str]) -> String {
let output = Command::new("wx-config")
.args(args)
.output()
.expect("failed execute wx-config command.");
String::from_utf8_lossy(&output.stdout).to_string()
fn wx_config(args: &[&str]) -> String {
if cfg!(windows) {
wx_config_win(args)
} else {
let output = Command::new("wx-config")
.args(args)
.output()
.expect("failed execute wx-config command.");
String::from_utf8_lossy(&output.stdout).to_string()
}
}

fn wx_config_win(args: &[&str]) -> String {
let wxwin = env::var("wxwin")
.expect("Set 'wxwin' environment variable to point the wxMSW binaries dir.");
let is_debug = env::var("PROFILE").unwrap() == "debug";
let d_or_not = if is_debug { "d" } else { "" };
if args.contains(&"--cflags") {
let mut cflags = vec![
format!("-I{}\\include", wxwin),
format!("-I{}\\lib\\vc14x_x64_dll\\mswu{}", wxwin, d_or_not),
"-DWXUSINGDLL".to_string(),
];
if is_debug {
cflags.push("-D_DEBUG".to_string());
} else {
cflags.push("-D__NO_VC_CRTDBG__".to_string());
cflags.push("-DwxDEBUG_LEVEL=0".to_string());
cflags.push("-DNDEBUG".to_string());
}
cflags.join(" ")
} else {
let libs = vec![
format!("-L{}\\lib\\vc14x_x64_dll", wxwin),
format!("-lwxbase31u{}", d_or_not),
format!("-lwxmsw31u{}_core", d_or_not),
];
libs.join(" ")
}
}