Rust Installation on Windows for developing GUI apps - windows

TL:DR;
Can I write GUI programs on Win 10 (64) using Rust without installing the full MinGW toolchain (nor the MS equivalent)?
Supplementary questions:
- If not, should I just go ahead and install MinGW?
- Does anything GNUish in Windows 10 Anniversary Update change any of this?
Longer version
I saw that Rust is the most loved programming language hereabouts so 15 minutes ago...
I read
No additional software installation is necessary for basic use of the GNU build.
Rust's support for the GNU ABI is more mature, and is recommended for typical uses.
So I downloaded Windows (GNU ABI †) (.msi) 64-bit to my PC running Windows 10.
TUI
I read some basic intro and used rustc to compile a Hello World! and ran it OK. I then read about cargo and reorganised buit and ran the same code using that.
GUI
I then searched for Rust GUI and found Kiss_UI
a simple UI tookit for Rust
So I did a cargo new Hello_GUI --bin and added
[dependencies.kiss-ui]
git = "https://github.com/cybergeek94/kiss-ui"
to Cargo.toml
I cut and pasted a simple example from that website into main.rs
I then ran cargo run --verbose. It did
Updating git repository `https://github.com/cybergeek94/kiss-ui`
Updating registry `https://github.com/rust-lang/crates.io-index`
Downloading iup-sys v0.0.3
Downloading libc v0.2.14
Downloading libc v0.1.12
Compiling libc v0.1.12
...
warning: crate `Hello_GUI` should have a snake case name such as `hello_gui`, #[warn(non_snake_case)] on by default
error: linking with `gcc` failed: exit code: 1
note: "gcc" "-Wl,--enable-long-section-names" ...
note: ld: cannot find -liup
error: aborting due to previous error
So I learned two things
I need to use snake case.
GUI programming is not "basic use".
I have no complaints about either of these points but could use a clue or two about the second:
Assuming I want to write a GUI equivalent of Hello World in a simple way, what are my main options now?

According to its documentation, kiss-UI depends on the IUP library.
The error from gcc (can't find -liup) suggests that you don't have IUP installed. You may be able to install it and have things work; it depends on whether the IUP bindings used by kiss-UI can cope with windows.
Some other GUI libraries can be found at awesome-rust. There are bindings to libraries like Qt and Gtk. If you know the windows API, you could also check out the winapi crate.
If you want to avoid messing with linking and stuff, you could try using a pure rust library like conrod, which should 'just work' on windows.
To answer your more broad questions:
See the footnote on the downloads page. The MSVC version of rust depends on MSVC being installed. The GNU/MinGW build is standalone.

Related

JSON-C build on Windows Platform

Disclaimer: Please read question carefully, This question has a twist so read it till end.
So JSON-C is one of the highly popular library to work on JSON using C programming. Basic illustration on current work, whatever code building here is for multi-platform. Currently Linux & Windows are supported platform and I have small issue with Windows related JSON-C part.
I'm using Cygwin for Windows development, and when I compile JSON-C code as per provided instruction on it's GitHub page, using CMAKE it works out quite good and build system is able generate DLLs for Windows. But if you have worked with Cygwin then you must know that whatever is built using Cygwin, will have dependency on it's run-time environment (cygwin1.dll) (Why does GCC-Windows depend on cygwin?) and it won't be an independent DLL that can be moved around to different system with same architecture. So with this dependency on Cygwin if my project is built on Windows platform, I have to carry around either Cygwin Run-Time Env. or I have to make sure Cygwin installed on target system for smooth execution. This sort of dependency I do not wish to have for my project, it can ruin user experience.
So what I want as help here, Is there a way to build JSON-C independent of Cygwin (run-time environment)??
NOTE: I already know that, if using Cygwin one wishes to create such an independent DLL for Windows then that can be done using few parameters to compiler and some additional macros placed in-front of function declaration as described here Creating a DLL in GCC or Cygwin?
But I don't see such support in source code JSON-C for Windows. So I was just wondering if JSON-C Dev team has kept some provision via build-system then I'm keen to know that part.
PS: I have not dipped into JSON-C build system yet due to my other development, so if anyone out there (my beloved community) has anything on this then please share, that would be terrific.
EDIT
Forgot to mention the version I'm using :p
json-c-0.13.1-20180305
I am able to build JSON-C 0.14-20200419 (from https://github.com/json-c/json-c) under MSYS2 with MinGW-w64 - both static and shared - using these instructions (replace /usr/local as needed):
INSTALLPREFIX=/usr/local
mkdir -p build_static build_shared &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=OFF -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_static &&
cmake.exe -Wno-dev -GNinja -DCMAKE_INSTALL_PREFIX:PATH=$INSTALLPREFIX -DCMAKE_BUILD_TYPE:STRING=Release -DBUILD_SHARED_LIBS:BOOL=ON -DBUILD_TESTING:BOOL=OFF -S. -Bbuild_shared &&
ninja -Cbuild_static install/strip &&
ninja -Cbuild_shared install/strip &&
echo Success
If you don't have ninja you can probably also use -G"MSYS Makefiles" and use make instead of ninja.
Note that MinGW-w64 is different from Cygwin in that it compiles to native Windows binaries without dependancies on a compatibility layer (like Cygwin's cygwin1.dll). The following screenshots illustrates this:

How to cross compile from Mac to Linux?

I wrote a little game using Rust, and I used cargo build --release to compile a release version on Mac.
I tried to share this with my friend who is using Ubuntu, but when he tried to run the binary, he got the following error:
cannot execute binary file: Exec format error
I searched for this but found no answers. Doesn't Rust claim to have "no runtime"? Shouldn't it be able to run anywhere in binary form?
Rust not having a runtime means that it doesn't have a lot of code running as part of the language (for example a garbage collector or bytecode interpreter). It does still need to use operating system primitives (i.e. syscalls), and these are different on MacOS and Linux.
What you want is a cross compiler. If you're using rustup, then installing a cross compiler should be simple:
# Install the toolchain to build Linux x86_64 binaries
rustup target add x86_64-unknown-linux-gnu
Then building is:
cargo build --release --target=x86_64-unknown-linux-gnu
Caveat: I don't have an OS X machine to test this on; please comment or edit to fix this if it works!
Well, it is because Rust has no runtime (unlike e.g. Java's JVM) that you can't just compile code on one OS and expect it to run on a different one; what you are looking for is cross-compilation. I haven't done it in Rust, but from what I can gather you can find relevant information on different cross-compilation Rust strategies on this GitHub repo.

How can I compile nDPI library on Windows?

The library comes with instructions on how to compile it on Linux:
./autogen.sh
./configure
make
But I can't find any source on the Internet to help me compile this code directly on Windows, just as if I never had a Linux machine.
nDPI is hosted here: https://github.com/ntop/nDPI
You could set up a linux-like CLI using Cygwin (very useful tool) and cross compile to Windows. It's not a complicated process and there is a lot of documentation around the Internet. I recommend using the MinGW 32 cross compiler.
You can use NFStream which provide Windows support and use nDPI as a DPI engine.
You have to edit some lines of source code and add the files
ntop_win32.h and ntop_win32.c
Then you can compile nDPI with Visual Studio.

Readline for windows - developing on linux

I am developing on linux, but still release binaries for windows.
I recently started using readline though, and that has broken my windows builds. Initially it was unable to find the header files, so I copied them to the mingw includes folder. However I still get problems linking to the library (cannot find -lreadline).
How do I get the readline library so that I can link to it in linux when compiling for windows?
Readline should just work, on Windows, I think, although you'll probably have to compile it yourself and bundle it with your program.
You'll need a replacement for ncurses though: pdcurses should do the job for you. Again, you'll probably have to build it yourself, I think.

Boost Jam Not Producing Thread Library on Windows

I downloaded the latest Boost Jam binary from SourceForge and I'm using the command:
bjam toolset=gcc --build-type=complete stage
I've installed Cygwin along with the GCC compiler. While the command produces a stage/lib directory, I cannot find the thread library that I'm using in Linux. Boost Jam takes a while to run, so there could have been errors along the way. Can anyone guess as to why I don't have the thread library? Is there a specific command I can run in an attempt to only build the thread library? Thanks!
You most definitely need to check for, and provide the error messages. You can also try passing either threadapi=pthread or threadapi=win32 to Boost.Build invocation.
In general, using the GNU/Kernel32.dll operating system, sometimes referred to as Cygwin, is risky business. Will using the native port of gcc, from mingw, be sufficient for you?

Resources