kenz-gelsoft / wxrust2 Goto Github PK
View Code? Open in Web Editor NEWre-exploration Rust binding to wx
License: MIT License
re-exploration Rust binding to wx
License: MIT License
To support deferred event handling.
wx/msw/wx.rc
into result binary with https://github.com/nabijaczleweli/rust-embed-resource or by other mean#include
-ing .xpm as C(++) source and provide its binary dataLink wx/msw/wx.rc into result binary with https://github.com/nabijaczleweli/rust-embed-resource or by other mean
as noted in https://www.wxwidgets.org/docs/faq/windows/#manifest
Some mechanisms implemented in the bining generator should have test. e.g.
To check memory leak, run this test with valgrind (or MSVC feature for leak check)
examples dir is conventional place easy to run in cargo
Small samples
Sample with variety widgets
Maybe by specifying Event types at Event class entry in toml
Hi
So I'm trying to build the hello sample on windows, Did set the wxwin env variable using a config.toml to the wx folder that comes with the repo that includes the dll's, Like this
config.toml:
``[env]
wxwin = { value = "../../wx", relative = true }
``
However
``error: failed to run custom build command for wx v0.1.0 (C:\Users\mohamed\projects\wxRust2\wx-core)
Caused by:
process didn't exit successfully: C:\Users\mohamed\projects\wxRust2\target\release\build\wx-52bbc0a6332a18a0\build-script-build
(exit code: 1)
--- stdout
TARGET = Some("x86_64-pc-windows-msvc")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
DEBUG = Some("false")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
CXX_x86_64-pc-windows-msvc = None
CXX_x86_64_pc_windows_msvc = None
HOST_CXX = None
CXX = None
CXXFLAGS_x86_64-pc-windows-msvc = None
CXXFLAGS_x86_64_pc_windows_msvc = None
HOST_CXXFLAGS = None
CXXFLAGS = None
CRATE_CC_NO_DEFAULTS = None
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-O2" "-Brepro" "-I" "C:\Users\mohamed\projects\wxRust2\samples\hello\../../wx\include" "-I" "C:\Users\mohamed\projects\wxRust2\samples\hello\../../wx\lib\vc14x_x64_dll\mswu" "-I" "include" "-W4" "/EHsc" "-DWXUSINGDLL=" "-D__NO_VC_CRTDBG__=" "-DwxDEBUG_LEVEL=0" "-DNDEBUG=" "-FoC:\Users\mohamed\projects\wxRust2\target\release\build\wx-7d5de0ba4c8730f8\out\src/manual.o" "-c" "src/manual.cpp"
manual.cpp
src/manual.cpp(1): fatal error C1083: Cannot open include file: 'wx/ctrlsub.h': No such file or directory
exit code: 2
--- stderr
error occurred: Command "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe" "-nologo" "-MD" "-O2" "-Brepro" "-I" "C:\Users\mohamed\projects\wxRust2\samples\hello\../../wx\include" "-I" "C:\Users\mohamed\projects\wxRust2\samples\hello\../../wx\lib\vc14x_x64_dll\mswu" "-I" "include" "-W4" "/EHsc" "-DWXUSINGDLL=" "-D__NO_VC_CRTDBG__=" "-DwxDEBUG_LEVEL=0" "-DNDEBUG=" "-FoC:\Users\mohamed\projects\wxRust2\target\release\build\wx-7d5de0ba4c8730f8\out\src/manual.o" "-c" "src/manual.cpp" with args "cl.exe" did not execute successfully (status code exit code: 2).
warning: build failed, waiting for other jobs to finish...
error: build failed
``
I'm probably missing a bunch of configuration steps, But it's hard to figure them out, So is there a configuration manual somewhere?
This is not a rare case:
And needs to be regenerated like this (ffbfc32...d4a7a39) after codegen change.
So codegen should support this scenario.
First of all very nice project, thanks!
I have a suggestion on simplifying the external dependency on wxWidgets installation by having pre-built crates for popular architectures and platforms, as an optional feature dependency.
This will give an advantage of much easier CI/CD setup and cross-platform builds. For those who need a system-specific library the wx-config
can still be used.
We are currently using this in our Rust project where wxWidgets is integrated via a custom C++ bridge and a few external crates which include wxWidgets binaries, examples:
https://github.com/ancwrd1/wx-universal-apple-darwin (macOS Intel + M1)
https://github.com/ancwrd1/wx-x86_64-pc-windows-gnu (Windows GNU toolchain)
Those binary crates can then be used via links
and DEP_xxx
cargo features in the build.rs:
use std::{env, error};
type BuildResult<T> = Result<T, Box<dyn error::Error>>;
fn dep_links() -> BuildResult<String> {
let target = env::var("TARGET")?.replace('-', "_").to_uppercase();
if target.contains("APPLE") {
Ok("UNIVERSAL_APPLE_DARWIN".to_owned())
} else {
Ok(target)
}
}
fn get_wx_cflags() -> BuildResult<Vec<String>> {
Ok(env::var(format!("DEP_WX_{}_CFLAGS", dep_links()?))?
.split_whitespace()
.map(ToOwned::to_owned)
.collect())
}
fn main() -> BuildResult<()> {
let (link_flags, build_flags): (Vec<_>, Vec<_>) = get_wx_cflags()?
.into_iter()
.partition(|f| f.starts_with("-l") || f.starts_with("-L"));
let mut build = cc::Build::new();
let target = env::var("TARGET")?;
build_flags
.iter()
.fold(&mut build, |build, f| build.flag(f))
.flag("-DNDEBUG")
.flag("-std=c++14")
.cpp(true)
.files(&[
"cxx/app.cpp",
]);
build.compile("libwxgui-cxx.a");
for f in link_flags {
println!("cargo:rustc-flags={}", f);
}
Ok(())
}
To follow the *-sys crate/package convention.
Blocks #72
Although it is a byproduct of the current least level abstraction.
Approaching alpha stage of this library, I'll update README of this project.
The following compilation errors are shown:
src/generated.cpp:823:18: error: ‘class wxWindow’ has no member named ‘RegisterHotKey’
src/generated.cpp:826:18: error: ‘class wxWindow’ has no member named ‘UnregisterHotKey’
I think this happens because those methods are only available on Windows.
after #51 fix this.
should mark them in doxybinding.toml and generate other code for them.
for better documentation and user ergonomics
Subsequent action of #119
In the same fashion that wxPython creates a wx namespace, use a more Rust-typical naming convention.
I'm new to rust and have installed rust and wxwidgets 3.2 using MSYS2 (for ucrt64, clang64, and mingw64 environments)
pacboy sync rust:u
pacboy sync rust:x
pacboy sync rust:c
pacboy sync wxwidgets3.2-msw:u
pacboy sync wxwidgets3.2-msw:x
pacboy sync wxwidgets3.2-msw:c
I get errors about setting the wxwin
environment variable.
I've tried setting them to many things in the MSYS2 environments, and even tried downloading the binary and development files from wxWidgets and pointing to them, but no luck.
Surely the wx-config --cflags
and wx-conig --libs
is all that is needed for the wxRust2
build system to find the headers and libraries. Yes/No?
Does wx-core/build.rs
need to be modified to support native MSYS2 installations of wxwidgets
?
What should I set wxwin
to - if anything at all?
$ find /mingw64 -type d -name "wx*"
/mingw64/include/wx-3.2
/mingw64/include/wx-3.2/wx
/mingw64/lib/wx
/mingw64/lib/wx/include/msw-unicode-3.2/wx
/mingw64/lib/wx/include/msw-unicode-static-3.2/wx
/mingw64/share/licenses/wxWidgets3.2
NOTE: I have wxRust2
running ok on macOS with brew installations of rust and wxwidgets.
i.e. I can build and run the samples.
I want to be able to do the same thing on Windows using MSYS2 installations of rust and wxwidgets.
--
Here is the output with wxwin
undefined.
$ cargo build -v
Compiling cc v1.0.72
Compiling wxrust-config v0.0.1-alpha2 (https://github.com/kenz-gelsoft/wxrust-vendored-config#245f52f7)
Running `rustc --crate-name cc --edition=2018 'C:\Users\BrendanSimon\.cargo\registry\src\index.crates.io-6f17d22bba15001f\cc-1.0.72\src\lib.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=197 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C metadata=789810fd6a5d8038 -C extra-filename=-789810fd6a5d8038 --out-dir 'C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' -L 'dependency=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' --cap-lints allow -C link-arg=-lstdc++`
Running `rustc --crate-name wxrust_config --edition=2021 'C:\Users\BrendanSimon\.cargo\git\checkouts\wxrust-vendored-config-2459bb25f7f509b9\245f52f\src\lib.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=197 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C metadata=a285a9de2a3a48ea -C extra-filename=-a285a9de2a3a48ea --out-dir 'C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' -L 'dependency=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' --cap-lints allow -C link-arg=-lstdc++`
Compiling wxrust-base v0.0.1-alpha (C:\Users\BrendanSimon\SW\wxRust2\wx-base)
Compiling wxrust v0.0.1-alpha (C:\Users\BrendanSimon\SW\wxRust2\wx-core)
Running `rustc --crate-name build_script_build --edition=2021 'wx-base\build.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=197 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C metadata=0eb8b6abd162f688 -C extra-filename=-0eb8b6abd162f688 --out-dir 'C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-base-0eb8b6abd162f688' -C 'incremental=C:\Users\BrendanSimon\SW\wxRust2\target\debug\incremental' -L 'dependency=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' --extern 'cc=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps\libcc-789810fd6a5d8038.rlib' --extern 'wxrust_config=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps\libwxrust_config-a285a9de2a3a48ea.rlib' -C link-arg=-lstdc++`
Running `rustc --crate-name build_script_build --edition=2021 'wx-core\build.rs' --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=197 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C metadata=e95e3129d44371d8 -C extra-filename=-e95e3129d44371d8 --out-dir 'C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-e95e3129d44371d8' -C 'incremental=C:\Users\BrendanSimon\SW\wxRust2\target\debug\incremental' -L 'dependency=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps' --extern 'cc=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps\libcc-789810fd6a5d8038.rlib' --extern 'wxrust_config=C:\Users\BrendanSimon\SW\wxRust2\target\debug\deps\libwxrust_config-a285a9de2a3a48ea.rlib' -C link-arg=-lstdc++`
Running `C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-base-0eb8b6abd162f688\build-script-build`
Running `C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-e95e3129d44371d8\build-script-build`
error: failed to run custom build command for `wxrust-base v0.0.1-alpha (C:\Users\BrendanSimon\SW\wxRust2\wx-base)`
Caused by:
process didn't exit successfully: `C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-base-0eb8b6abd162f688\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Set 'wxwin' environment variable to point the wxMSW binaries dir.: NotPresent', C:\Users\BrendanSimon\.cargo\git\checkouts\wxrust-vendored-config-2459bb25f7f509b9\245f52f\src\lib.rs:54:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `wxrust v0.0.1-alpha (C:\Users\BrendanSimon\SW\wxRust2\wx-core)`
Caused by:
process didn't exit successfully: `C:\Users\BrendanSimon\SW\wxRust2\target\debug\build\wxrust-e95e3129d44371d8\build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'Set 'wxwin' environment variable to point the wxMSW binaries dir.: NotPresent', C:\Users\BrendanSimon\.cargo\git\checkouts\wxrust-vendored-config-2459bb25f7f509b9\245f52f\src\lib.rs:54:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Thanks :)
Today, it is released!
https://www.wxwidgets.org/news/2022/07/wxwidgets-3.2.0-final-release/
Target it for development. For a while keep buildable for
Work items:
For crates.io publish:
wxObjects in widget tree are managed its lifetime by the toolkit.
Pointers returned from API other than constructors or methods explicitly passes ownership may be dangling pointer.
Those pointers should have safer interface.
Other value types use struct with Drop, but for string directly returns new-ed pointers but wont be deleted...
We should have some type of tests for memory management like this.
I made builders for some GUI classes used in porting sample code.
In #119, many new classes are generated, without builders. More builders may be required(or requested).
For a while, I'll make new builders per request (by users, mainly me)
wx manages (almost all) wxWindows' pointers which is in widgets tree.
This means that any operation potentially makes any pointers invalid.
This should be expressed unsafe
in Rust, how can we do this?
Items noticed in #119
Treatment on these should reduce lines of https://github.com/kenz-gelsoft/wxRust2/blob/main/doxybindgen.toml (and result fewer work to generate more/new classes/APIs)
kenz@KENZnoMacBook-Air wx-base % cargo publish
Updating crates.io index
error: all dependencies must have a version specified when publishing.
dependency `wx-universal-apple-darwin` does not specify a version
Note: The published dependency will use the version from crates.io,
the `git` specification will be removed from the dependency declaration.
Items:
As this represents the concept clearer and can be distinguished from Rust's owned type.
also rename Unowned -> InCxx/InCpp/FromCpp
This class is documented as it is-a wxTextCtrl,
https://docs.wxwidgets.org/3.2/classwx_search_ctrl.html
but it isn't.
https://github.com/wxWidgets/wxWidgets/blob/v3.2.0/include/wx/srchctrl.h#L26
it actually mimic the wxTextCtrl API through wxTextCtrlIface. so can't static_cast<wxTextCtrl*>()
.
This result the generated code fails to compile:
// Mix-in(s) to wxSearchCtrl
wxTextEntry *wxSearchCtrl_AsTextEntry(wxSearchCtrl* obj) {
return static_cast<wxTextEntry*>(obj);
}
Steps:
Current binding requires many boilerplate code with constructor's default arguments.
https://github.com/kenz-gelsoft/wxRust2/blob/main/samples/wrapsizer/src/main.rs
is example.
Write manually builder pattern constructor.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.