[DSP] Rust + QML + macOS

by Paweł Świątkowski
14 Apr 2017

My project came to a bit of a stall lately, but today I decided to try to push it through a bit. Unfortunately, before I was doing most of development on my Linux-powered laptop, but this time I only had a Mac available. But what’s the difference?, I thought, after all both are UNIX-based and Mac aficionados can’t stop talking about how everything Just Works™ there…

Almost an hour later, I finally managed to run my example Rust + QML app I wrote about recently. I was close to giving up, because I easily got it to compile, but the linker would not work, claiming that it can’t find Qt libraries. Indeed, Qt installation from homebrew is a bit weird and even warned me about that. Fortunately I found an issue (quite recent one) explaining how to go.

To get through it, you need to use a mechanism in Cargo that lets you set up environment before running actual compilation. So, you ned to create a build.rs file in the root of your project with following content:

fn main() {
  println!("cargo:rustc-link-search=framework=/usr/local/opt/qt5/Frameworks");
  println!("cargo:rustc-link-lib=c++");
}

Then in Cargo.toml you add:

build = "build.rs"

Et Voila! It works. However I’m a bit puzzled now - should I check those files into version control? Wouldn’t they break builds on other platforms? I was experimenting with other approaches, as apparently build script might be overriden in config, however I didn’t get it to work. Maybe some day…

end of the article

Tags: dsp rust qt qml macos

This article was written by me – Paweł Świątkowski – on 14 Apr 2017. I'm on Fediverse (Ruby-flavoured account, Elixir-flavoured account). Let's talk.