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

Help getting samples going with MSYS2 installation of wxWidgets #190

Open
brendan-simon-indt opened this issue Jul 3, 2023 · 3 comments

Comments

@brendan-simon-indt
Copy link

brendan-simon-indt commented Jul 3, 2023

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
Copy link
Author

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

@kenz-gelsoft
Copy link
Owner

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.

#[cfg(all(not(feature = "vendored"), windows))]
pub fn wx_config(args: &[&str]) -> Vec<String> {
let wxwin = env::var("wxwin")
.expect("Set 'wxwin' environment variable to point the wxMSW binaries dir.");
// TODO: support linking with the wx debug DLL
let is_debug = false; //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());
}
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
if target_env.eq("msvc") {
cflags.push("/EHsc".to_string());
}
cflags
} else {
let libs = vec![
format!("-L{}\\lib\\vc14x_x64_dll", wxwin),
format!("-lwxbase32u{}", d_or_not),
format!("-lwxmsw32u{}_core", d_or_not),
];
libs
}
}

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:

rustflags = "-C link-arg=-lstdc++"

For more context, see #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.

@brendan-simon-indt
Copy link
Author

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 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants