Giter Site home page Giter Site logo

wxrust2's Introduction

wxRust2

This is my 2nd exploration of binding the wxWidgets cross-platform toolkit.

This project is in the very-early stage of the development. I'm playing with this in my very limited spare time. So don't expect this project will be usable (or useful) state in the near future.


How to use

  1. Install prerequisite or Specify feature to use vendored wx binary crate
  2. Specify wxrust dependency
    [dependencies]
    wx = { version = "0.0.1-alpha", package = "wxrust" }

See documentation (after crate released) or wx-core/README.md for more details.

Prerequisite

Install the wxWidgets library. Currently (not fully) supported library versions:

wx Windows macOS Linux
3.2.0 Installed Official MSVC DLL Homebrew Codelite repo
3.2.0 Vendored MinGW64 Static Universal Static N/A
3.0.5 N/A N/A Ubuntu Package

Following installation method are (somewhat) tested with:

Windows

macOS

  • Install from Homebrew like brew install wxwidgets

Linux

Use vendored wx binary crate

You can use prebuilt wx binaries without installing wxWidgets system-wide.

  1. Specify --features vendored to cargo.
  2. Override wxrust-config crate dependency with the following git respositry crate (or your fork of it):
    [patch.crates-io]
    wxrust-config = { git = "https://github.com/kenz-gelsoft/wxrust-vendored-config" }
    • You need to specify git or local separate repo's crate, as crates.io won't host crates with (large) binary crates such as this.

This configuration links to following per-build-target crates by default. You should be able to override this by crate name:

Build target Crate name Git repository Build configuration
cfg(target_os = "macos") wx-universal-apple-darwin https://github.com/ancwrd1/wx-universal-apple-darwin Lean and mean config, see repo.
x86_64-pc-windows-gnu wx-x86_64-pc-windows-gnu https://github.com/ancwrd1/wx-x86_64-pc-windows-gnu Lean and mean config, see repo.
x86_64-pc-windows-msvc wx-x86_64-pc-windows-msvc https://github.com/kenz-gelsoft/wx-x86_64-pc-windows-msvc Bundled wx3.2.0 official build

@ancwrd1 suggested this feature and kindly helped to support this. Thank you!


License

MIT License. but you can (and shoudld) treat this library as wxWindows Library Licence (same with required wxWidgets library dependency).

Large part of this project is the binding generator in Python (doxybindgen). This part may be usable and want to be used for another traditional C++ APIs with Doxygen documented (c.f. like Haiku OS APIs(Kits)) in future. So permissive license is desirable.

Samples ported from wxWidgets

samples/ subdirectory contains sample codes ported from the wxWidgets Library. These sample codes are licensed under the wxWindows Library Licence.

wxrust2's People

Contributors

dependabot[bot] avatar kenz-gelsoft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wxrust2's Issues

Steps for building on windows?

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?

Help getting samples going with MSYS2 installation of wxWidgets

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 :)

Handle specially wxSearchCtrl which isn't wxTextCtrl on MSW

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);
}

Generate rest of wxCore library classes

Steps:

  • Make codegen more scalable
    • #121
    • Some more automatic codegen
    • Split generated file in handy size
      • Very large generated file cannot be handled well in github.
  • List classes by libname
    • by using script
  • Generate all classes in core library
  • Mark classes used in sample programs
    • may need to incorporate manual annotation into above script
    • will do in #145
  • Add manual supplement binding code for newly generated classes

Target wxWidgets 3.2.0

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

  • 3.0(last stable version),
    • I gave up supporting this as noted in #92 (comment)
    • will support wx3.0 GTK+3 build again in #96
  • 3.1.7(until homebrew and some linux distros packages 3.2 series), Dropped rolling releases catch up it
  • 3.1.6(until prebuilt crates update)

Work items:

  • update wxml/ doxygen xml output
  • re-gen binding for it and fix build errors
  • update my prebuilt msvc crate packaging official binary

Consider safety of almost all API calls

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?

Dependency on vendored repo blocks publishing

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.

Minimal example fails to compile under Linux

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.

Add memory management tests

Some mechanisms implemented in the bining generator should have test. e.g.

  • String parameter marshalling
  • Value types dropped correctly
  • Windows to be deallocated when their parent destroyed (especially when top level window closed)
  • Windows leak if they are created but not added to parent (This is intentional for now)
  • WeakRef to(wx)Trackables works correctly

To check memory leak, run this test with valgrind (or MSVC feature for leak check)

  • ideally integrate this in CI
  • at least document how to run leak check as a manual step to release this library

Consider using a "vendored" wxWidgets dependency

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(())
}

Port more examples and generate more wx-core classes

Small samples

Sample with variety widgets

Clean up sample code

  • Remove/reduce unsafe code
  • Stop wx classes deriving Clone trait
    • It should be replaced with wx::WeakRef
    • as_weak_ref() or such on wx::Trackable needed

Windows specific tasks

  • copy DLLs on cargo build
  • fix crash on returning wxString as rust String
    • found on win32 debug build run, but it may be common problem on all platforms.
    • work in #36
  • setup github build action
    • considering to install wxwidgets dependency with vcpkg
    • will achieved in #91

Support up/down cast

  • upcasting is safe and should succeed.
  • downcasting can fail, but should be safe.
    • try_ somthing naming is desired.

Make wxWeakRef-like for wx managed pointers

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.

Change crate name and versioning

For crates.io publish:

  • Crate names
    • Since wx crate name is already popular for wechat(weixin?) SDK
    • Candidates:
      • wxwidgets
      • wxwidgets-base
  • Versioning
    • 0.0.x
    • Since there's no API stability as we map C++ overload to method name
    • Compatible C++ API change may be break compatiblity in this lib

More automatic codegen

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)

  • Block ctor on abstract class
  • Block methods using template in args
    • This may be handled wiith hand-written binding, should place comment in generated code?
  • Block operator overloads (which isn't supported yet)
    • Register an issue with this if block this automatically
  • Block using wx-value types without pointer/ref (which isn't supported yet, or cannot be done automatically)
    • Register an issue with this if block this automatically

(Maybe) all allocated wxStrings are leaked

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.