woboq / qmetaobject-rs

Integrate Qml and Rust by building the QMetaObject at compile time.
MIT License
633 stars 89 forks source link

Cannot build example on macOS #7

Closed nbigaouette closed 6 years ago

nbigaouette commented 6 years ago

I'd like to explore this crate but I have trouble building a hello world (or even the provided examples) on macOS High Sierra 10.13.5 (17F77).

Cargo.toml

First issue is providing a Cargo.toml with git dependency. I have the followin dependencies section:

[dependencies]
cstr = "0.1.4"
qmetaobject = { git = "https://github.com/woboq/qmetaobject-rs.git" }

but getting this error:

cargo run -v
    Updating git repository `https://github.com/woboq/qmetaobject-rs.git`
error: failed to load source for a dependency on `qmetaobject`

Caused by:
  Unable to update https://github.com/woboq/qmetaobject-rs.git

Caused by:
  Could not find `Cargo.toml` in `/home/rust/qml-rust`

Could it be a cargo bug? Why would it want to clone the repo into /home/rust?

The only way to pass this step is to manually clone the repo and use path instead:

qmetaobject = { path = "../qmetaobject-rs/qmetaobject" }

Linking

On macOS, I've installed Qt 5.11 through hombrew:

brew install qt

This installs Qt in /usr/local/Cellar/qt/5.11.0, which is symlinked to /usr/local/opt/qt. Looking at the crate's build.rs it seems qmake needs to be in the PATH to find everything, so I run cargo like this:

PATH="/usr/local/opt/qt/bin:$PATH" cargo build -v

but I get a linking error:

 -> PATH="/usr/local/opt/qt/bin:$PATH" cargo run -v
       Fresh unicode-xid v0.0.4
       Fresh quote v0.3.15
       Fresh libc v0.2.42
       Fresh unicode-xid v0.1.0
       Fresh cc v1.0.17
       Fresh lazy_static v0.2.11
       Fresh byteorder v1.2.3
       Fresh procedural-masquerade v0.1.6
       Fresh lazy_static v1.0.1
       Fresh cpp_synom v0.12.0
       Fresh memchr v1.0.2
       Fresh memchr v2.0.1
       Fresh proc-macro2 v0.2.3
       Fresh proc-macro2 v0.3.8
       Fresh cpp_syn v0.12.0
       Fresh aho-corasick v0.6.4
       Fresh quote v0.4.2
       Fresh syn v0.13.11
       Fresh cpp_common v0.3.2 (https://github.com/ogoffart/rust-cpp#53a2a523)
       Fresh cpp_synmap v0.3.0 (https://github.com/ogoffart/rust-cpp#53a2a523)
       Fresh syn v0.12.15
       Fresh cstr-macros v0.1.3
       Fresh cpp_macros v0.3.2 (https://github.com/ogoffart/rust-cpp#53a2a523)
       Fresh cpp_build v0.3.2 (https://github.com/ogoffart/rust-cpp#53a2a523)
       Fresh qmetaobject_impl v0.1.0 (file:///Users/nbigaouette/qmetaobject-rs/qmetaobject_impl)
       Fresh cstr v0.1.4
       Fresh cpp v0.3.2 (https://github.com/ogoffart/rust-cpp#53a2a523)
       Fresh qmetaobject v0.1.0 (file:///Users/nbigaouette/qmetaobject-rs/qmetaobject)
   Compiling qrs v0.1.0 (file:///Users/nbigaouette/qrs)
     Running `rustc --crate-name qrs src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fdbad780bdb6e4fd -C extra-filename=-fdbad780bdb6e4fd --out-dir /Users/nbigaouette/qrs/target/debug/deps -C incremental=/Users/nbigaouette/qrs/target/debug/incremental -L dependency=/Users/nbigaouette/qrs/target/debug/deps --extern cstr=/Users/nbigaouette/qrs/target/debug/deps/libcstr-229389dca99a215e.rlib --extern qmetaobject=/Users/nbigaouette/qrs/target/debug/deps/libqmetaobject-f8cf0d799f0a6e78.rlib -L native=/Users/nbigaouette/qrs/target/debug/build/qmetaobject-b403b05d424a923c/out -L /usr/local/Cellar/qt/5.11.0/lib`
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-m64" "-L" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.138pesuvab4dy035.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.158wz1xuz2s5vbhj.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.16u6js6g0l3k1ic6.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1ckp3bwk0jmrbky4.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1im38lueib99jsk0.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1mvmz58owquyropc.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1u1h5nktjnbdixm9.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1y16o1qfye96o7m0.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1zeawhkbeobww1zn.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.1zwd8n7bcl3vhvvh.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.21lmh9el3s7qewmf.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.236iz806sghm3wx.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.23tqyymcb18u96mb.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.2h6js7r1t4ms8cda.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.2jqywn86b2gsqohu.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.2lyh15q6cjwzy18c.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3171x0bwu82dptu7.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3ayaeypdcro9d6yk.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3cx7oljifvb206q7.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3ik0x0hz6l66cx38.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3oqznv5oym7l3m4e.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.3rngp6bm2u2q5z0y.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.436dotimmrgzkwfa.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.45nf4z58qqykpcpi.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.45pc7c65foh9i35f.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.48721dc4k5qxei0u.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.48js8ox6iz7qimsy.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.49a7n47po4ttqjl7.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.49lx1q7cxvpykyv0.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.4ezmh1vbs95c5ack.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.4muxhhwheabhmfrq.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.4xq48u46a1pwiqn7.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.4yh8x2b62dcih00t.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.4ypvbwho0bu5tnww.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.54zq6xwdlu4umqga.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.57k06xfugllsc526.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.5gf6du7k58s78kob.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.8xzrsc1ux72v29j.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.98g0d9x8aw3akpe.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.9elsx31vb4it187.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.c6lbtaiefvx3wya.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.gon14xphovlcp6p.rcgu.o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.lkwxa5jxocp5cdw.rcgu.o" "-o" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd" "/Users/nbigaouette/qrs/target/debug/deps/qrs-fdbad780bdb6e4fd.crate.allocator.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/nbigaouette/qrs/target/debug/deps" "-L" "/Users/nbigaouette/qrs/target/debug/build/qmetaobject-b403b05d424a923c/out" "-L" "/usr/local/Cellar/qt/5.11.0/lib" "-L" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/nbigaouette/qrs/target/debug/deps/libcstr-229389dca99a215e.rlib" "/Users/nbigaouette/qrs/target/debug/deps/libprocedural_masquerade-7c03427e39d1509c.rlib" "/Users/nbigaouette/qrs/target/debug/deps/libqmetaobject-f8cf0d799f0a6e78.rlib" "/Users/nbigaouette/qrs/target/debug/deps/liblazy_static-06ef2c3f75526230.rlib" "/Users/nbigaouette/qrs/target/debug/deps/libcpp-debeb2ed315e6ace.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-47f9a7ab54e7fd55.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-34945e660c1550db.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-78b7d62b8a210d08.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-2582c6ee1d80b6ff.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc_system-7c3c30d2aa65bfa1.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-721ecb302a549dca.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-32f8204d813d7d31.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd_unicode-771b444d7a99c1b3.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-0c8375020799bd23.rlib" "/Users/nbigaouette/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-95d524c979807816.rlib" "-l" "c++" "-l" "Qt5Widgets" "-l" "Qt5Gui" "-l" "Qt5Core" "-l" "Qt5Quick" "-l" "Qt5Qml" "-l" "System" "-l" "resolv" "-l" "pthread" "-l" "c" "-l" "m"
  = note: ld: library not found for -lQt5Widgets
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: aborting due to previous error

error: Could not compile `qrs`.

Caused by:
  process didn't exit successfully: `rustc --crate-name qrs src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=fdbad780bdb6e4fd -C extra-filename=-fdbad780bdb6e4fd --out-dir /Users/nbigaouette/qrs/target/debug/deps -C incremental=/Users/nbigaouette/qrs/target/debug/incremental -L dependency=/Users/nbigaouette/qrs/target/debug/deps --extern cstr=/Users/nbigaouette/qrs/target/debug/deps/libcstr-229389dca99a215e.rlib --extern qmetaobject=/Users/nbigaouette/qrs/target/debug/deps/libqmetaobject-f8cf0d799f0a6e78.rlib -L native=/Users/nbigaouette/qrs/target/debug/build/qmetaobject-b403b05d424a923c/out -L /usr/local/Cellar/qt/5.11.0/lib` (exit code: 101)

I think it could be related to println!("cargo:rustc-link-lib=Qt5Widgets"); being used instead of macOS framework. I'll try to plain with this...

nbigaouette commented 6 years ago

I was able to build tweaking the build.rs file:

diff --git a/qmetaobject/build.rs b/qmetaobject/build.rs
index 8942f89..45e43c5 100644
--- a/qmetaobject/build.rs
+++ b/qmetaobject/build.rs
@@ -32,10 +36,10 @@ fn main() {
         .include(qt_include_path.trim())
         .build("src/lib.rs");

-    println!("cargo:rustc-link-search={}", qt_library_path.trim());
-    println!("cargo:rustc-link-lib=Qt5Widgets");
-    println!("cargo:rustc-link-lib=Qt5Gui");
-    println!("cargo:rustc-link-lib=Qt5Core");
-    println!("cargo:rustc-link-lib=Qt5Quick");
-    println!("cargo:rustc-link-lib=Qt5Qml");
+    println!("cargo:rustc-link-search=framework={}", qt_library_path.trim());
+    println!("cargo:rustc-link-lib=framework=QtWidgets");
+    println!("cargo:rustc-link-lib=framework=QtGui");
+    println!("cargo:rustc-link-lib=framework=QtCore");
+    println!("cargo:rustc-link-lib=framework=QtQuick");
+    println!("cargo:rustc-link-lib=framework=QtQml");
 }

I'll submit a PR with a cleanup version.

ogoffart commented 6 years ago

The problem with /home/rust seems to lie in the fact that there is a benchmark that tries to reference hardcoded paths: https://github.com/woboq/qmetaobject-rs/blob/72baa6dc53a74bb152e53fda280bab9ba97c5406/benchmark/qml-rust/Cargo.toml#L7 and cargo tries to build it.

The problem is that the version on crates.io is too lod for my system.

I guess i'll just remove these benchmarks.