wxRust2 icon indicating copy to clipboard operation
wxRust2 copied to clipboard

Help getting samples going with MSYS2 installation of wxWidgets

Open brendan-simon-indt opened this issue 1 year ago • 3 comments

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

brendan-simon-indt avatar Jul 03 '23 12:07 brendan-simon-indt

Please help !! I'm keen to get this going and move on to supporting rust generated code from wxGlade :)

brendan-simon-indt avatar Jul 13 '23 13:07 brendan-simon-indt

Hello, Brendan,

I'm sorry for too late reply. As I recently dedicated whole my spare time to another project these days.

I have not been tried wxRust2 with MSYS2 environment generally. So my answer is not (yet) tested.

At first, non-vendored, non-MSVC build of wxwidgets is not supported yet.

I get errors about setting the wxwin environment variable.

The wxwin environment variable used here for MSVC build. This function should support another configurations, but not supported yet. So, just setting wxwin to any value should not work.

https://github.com/kenz-gelsoft/wxRust2/blob/43ec9e55ad54dea163a3a6f8bfb2cd9a7d23750c/wxrust-config/src/lib.rs#L61-L94

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?

Theoretically, YES.

It is rather compilcated as we have wxrust-config subcrate to integrate vendored binary.

Does wx-core/build.rs need to be modified to support native MSYS2 installations of wxwidgets?

May or may not. If you want simplify things to investigate in your source tree, change like this locally

wx-base/build.rs

// COMMENT OUT
// use wxrust_config::wx_config;

fn main() {
    let mut cc_build = cc::Build::new();
    // from `wx-config --cflags`
    // CHANGE BELOW LINE
    //let cflags = wx_config(&["--cflags"]);
    let cflags = vec![
        "PLACE YOUR".to_string(),
        "wx-config --cflags".to_string(),
        "OUTPUT, HERE.".to_string(),
    ];
    for arg in cflags.iter() {
        cc_build.flag(arg);
    }
    cc_build
        .cpp(true)
        .file("src/manual.cpp")
        .file("src/generated/events.cpp")
        .file("src/generated.cpp")
        .include("include")
        .flag_if_supported("-std=c++14")
        // ignore too many warnings with wx3.0
        .flag_if_supported("-Wno-deprecated-copy")
        .flag_if_supported("-Wno-ignored-qualifiers")
        .flag_if_supported("-Wno-unused-parameter")
        .compile("wx");

    // from `wx-config --libs`
    // CHANGE BELOW LINE TOO
    //let libs = wx_config(&["--libs"]);
    let libs = vec![
        "PLACE YOUR".to_string(),
        "wx-config --libs".to_string(),
        "OUTPUT, HERE.".to_string(),
    ];
    println!("cargo:rustc-flags={}", libs.join(" "));
}

Change wx-core/build.rs too.

Additionally, rust projects (your application) which uses wxRust2 may need to specify RUSTFLAGS to -C link-arg=-lstdc++ or so. This is integrated our CI environment like this:

https://github.com/kenz-gelsoft/wxRust2/blob/43ec9e55ad54dea163a3a6f8bfb2cd9a7d23750c/.cargo/config.toml#L5

For more context, see https://github.com/kenz-gelsoft/wxRust2/pull/91.

If you successfully build with some modification on your environment, I'll try integrate your modifications.

Of course, a PR is welcome as a starting point.

kenz-gelsoft avatar Aug 19 '23 22:08 kenz-gelsoft

Thanks for the info. I will take a closer look when I get a chance.

BTW, the install on Mac with brew worked easily and I was able to test the examples. Seems very promising - all the widgets seem to work and render ok. Seems like writing useful applications should be possible 😃

brendan-simon-indt avatar Aug 21 '23 00:08 brendan-simon-indt