aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml5
-rw-r--r--build.rs75
-rw-r--r--examples/frame-demo.rs1
-rw-r--r--examples/hello-world.rs20
-rw-r--r--src/lib.rs29
-rw-r--r--src/wx-sys.cpp6
-rw-r--r--src/wx-sys.h4
7 files changed, 56 insertions, 84 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3dd46f0..9adf0f2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,8 +3,11 @@ name = "shit-wx-sys"
version = "0.1.0"
edition = "2021"
+[dependencies]
+cxx = "1.0"
+
[build-dependencies]
anyhow = "1.0.44"
-bindgen = { version = "0.59.1" }
+cxx-build = "1.0"
ureq = "2.3.0"
url = "2.2.2"
diff --git a/build.rs b/build.rs
index f22e64f..adc18c6 100644
--- a/build.rs
+++ b/build.rs
@@ -96,67 +96,31 @@ fn build_x64_windows_msvc() -> Result<()> {
let out_dir = out_dir();
// TODO consider actually parsing wxwidgets.props at build time instead of doing it manually
- // TODO bindgen ahead of time
- // TODO can we really get away with this to do static linking
- let wx_using_lib = true;
- if wx_using_lib {
- let dll_folder = out_dir.join("lib/vc14x_x64_dll");
- let lib_folder = out_dir.join("lib/vc14x_x64_lib");
- if dll_folder.exists() && !lib_folder.exists() {
- fs::rename(dll_folder, lib_folder)?;
- }
- }
- let libs_folder = out_dir.join(if wx_using_lib {
- "lib/vc14x_x64_lib"
- } else {
- "lib/vc14x_x64_dll"
- });
- let wx_using_dll = !wx_using_lib;
+ // 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 defines = vec![
- "__WXMSW__",
- "wxMSVC_VERSION_AUTO",
- "wxMSVC_VERSION_ABI_COMPAT",
- "_UNICODE",
- ];
- if debug {
- defines.push("_DEBUG");
- }
- if wx_using_dll {
- defines.push("WXUSINGDLL");
- }
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 bindings = bindgen::Builder::default()
- .header("wrapper.hpp")
- // pain
- .clang_arg("-Wno-invalid-token-paste")
- .clang_args(defines.iter().map(|x| format!("-D{}", x)))
- // TODO don't .display()
- .clang_args(include_dirs.iter().map(|x| format!("-I{}", x.display())))
- .opaque_type("std::.*")
- // pain 2: the sequel to pain
- .blocklist_type("CharType")
- .blocklist_type("value_type")
- .blocklist_type("const_reference")
- // pain 3: the shriequel to pain
- .blocklist_type("wxBaseArray_CMPFUNC")
- .blocklist_type("wxBaseObjectArray")
- .blocklist_type("wxBaseObjectArray_base")
- .blocklist_type("pointer")
- .blocklist_type("const_pointer")
- .blocklist_type("wxBaseObjectArrayForwxDateTimeArray")
- .blocklist_type("wxBaseObjectArrayForwxIconArray")
- .blocklist_type("wxBaseObjectArrayForwxStatusBarPaneArray")
- .opaque_type("_IMAGE_TLS_DIRECTORY64")
- // that's enough pain? maybe?
- .generate()
- .map_err(|_| anyhow!("failed to generate bindings"))?;
- let out_path = out_dir.join("bindings.rs");
- bindings.write_to_file(&out_path)?;
+
+ cxx_build::bridge("src/lib.rs")
+ .file("src/wx-sys.cpp")
+ .includes(include_dirs)
+ .flag_if_supported("-Wno-invalid-token-paste")
+ .define("__WXMSW__", None)
+ .define("wxMSVC_VERSION_AUTO", None)
+ .define("wxMSVC_VERSION_ABI_COMPAT", None)
+ .define("_UNICODE", None)
+ .define("WXUSINGDLL", None)
+ .flag_if_supported("-std=c++14")
+ .flag_if_supported("/std:c++14")
+ .compile("shit-wx-sys");
+
+ println!("cargo:rerun-if-changed=src/lib.rs");
+ println!("cargo:rerun-if-changed=src/wx-sys.h");
+ println!("cargo:rerun-if-changed=src/wx-sys.cpp");
let win32_libs = [
"kernel32", "user32", "gdi32", "comdlg32", "winspool", "shell32", "shlwapi", "ole32",
@@ -171,7 +135,6 @@ fn build_x64_windows_msvc() -> Result<()> {
println!("cargo:rustc-link-search=native={}", libs_folder.display());
// TODO which libs do we actually want to link
- println!("cargo:rustc-link-lib=static=wxbase31{}", wx_suffix);
println!("cargo:rustc-link-lib=static=wxmsw31{}_core", wx_suffix);
Ok(())
}
diff --git a/examples/frame-demo.rs b/examples/frame-demo.rs
index 2b69eb7..c422bdb 100644
--- a/examples/frame-demo.rs
+++ b/examples/frame-demo.rs
@@ -6,6 +6,7 @@ use std::ptr::{null, null_mut};
use shit_wx_sys::*;
fn main() {
+ #[cfg(unix)]
unsafe {
let app = wxApp::new();
diff --git a/examples/hello-world.rs b/examples/hello-world.rs
index 9fe521c..9928016 100644
--- a/examples/hello-world.rs
+++ b/examples/hello-world.rs
@@ -1,21 +1,5 @@
-use std::ffi::CString;
-use std::ptr::null_mut;
-
-use shit_wx_sys::*;
+use shit_wx_sys as wx;
fn main() {
- unsafe {
- let message = "It's alive!!";
- let c_string_message = CString::new(message).unwrap();
- let message =
- wxString::FromAscii(c_string_message.as_ptr(), message.len().try_into().unwrap());
- wxMessageBox(
- (&message) as *const wxString,
- (&message) as *const wxString,
- (wxOK as i32) | wxGeometryCentre_wxCENTER,
- null_mut(),
- wxDefaultCoord,
- wxDefaultCoord,
- );
- }
+ wx::message_box();
}
diff --git a/src/lib.rs b/src/lib.rs
index dca544b..44af2fe 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,9 +1,20 @@
-#![allow(
- non_camel_case_types,
- non_snake_case,
- unaligned_references,
- non_upper_case_globals,
- deref_nullptr
-)]
-
-include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
+#[cxx::bridge]
+mod ffi {
+ unsafe extern "C++" {
+ include!("shit-wx-sys/src/wx-sys.h");
+
+ fn message_box();
+ }
+}
+
+pub use ffi::*;
+
+#[cfg(test)]
+mod test {
+ use super::*;
+
+ #[test]
+ fn test_message_box() {
+ message_box();
+ }
+}
diff --git a/src/wx-sys.cpp b/src/wx-sys.cpp
new file mode 100644
index 0000000..8e07962
--- /dev/null
+++ b/src/wx-sys.cpp
@@ -0,0 +1,6 @@
+#include "shit-wx-sys/src/wx-sys.h"
+#include <wx/msgdlg.h>
+
+void message_box() {
+ wxMessageBox("Hello World!!!");
+}
diff --git a/src/wx-sys.h b/src/wx-sys.h
new file mode 100644
index 0000000..68c4484
--- /dev/null
+++ b/src/wx-sys.h
@@ -0,0 +1,4 @@
+#include "rust/cxx.h"
+#include <memory>
+
+void message_box();