erickt / rust-zmq

Rust zeromq bindings.
Apache License 2.0
900 stars 194 forks source link

Introduce `static-libzmq` crate feature for easier building of zmq crate. #241

Closed oblique closed 5 years ago

oblique commented 5 years ago

Since @zachlute is not that active I open this PR which contains his and my changes. This PR replaces #239.

This PR introduces a crate feature static-libzmq which builds libzmq and statically links it to the binary. This makes it easier for the users to use zmq crate without building libzmq on their own. It is tested on Windows and Linux. It is also tested in Linux embedded environments that cross-compilation is a must. Users are required to have cmake installed.

Let know what improvements/changes you may need.

zachlute commented 5 years ago

It's unclear to me what 'not that active' means in this case, since I've responded pretty immediately to all comments and suggestions you made on the other PR. Nothing has happened with it in weeks, so I'm not sure what exactly wasn't active enough for you?

That said, I like your improvements and I don't have any particular desire to own this change, beyond the work I've already done to make it work for me, so /shrug. I'll close the other PR.

oblique commented 5 years ago

@zachlute Hey, sorry, I opened you another PR with two more commits in your fork and because you didn't merge it I though you don't check your account regularly. Sorry again.

zachlute commented 5 years ago

@oblique My apologies. Most of my projects aren't on github, so I usually only check it when I get a notification email, and I just verified I never got a notification email for that PR, so that's weird and I should probably figure out why I'm not getting those.

Turns out I'm an inactive deadbeat after all. Carry on. :)

hansieodendaal commented 5 years ago

Hi @oblique , I tried to compile your branch https://github.com/oblique/rust-zmq/tree/build-zmq, but got some errors.

We use the latest version of libzmq (v4.3.2), which I compiled with Visual Stuio 2017 using the CMake -> Install -> ZeroMQ menu option. I also copied the static lib from libzmq-mt-s-4_3_2.lib to zmq.lib in the lib folder.

Compiling I get the following error, which is the similar to what I get when compiling from master at https://github.com/erickt/rust-zmq

C:\Users\me\Documents\Code\zmq\rust-zmq-oblique>cargo build
   Compiling error-chain v0.10.0
   Compiling cc v1.0.31
   Compiling pkg-config v0.3.14
   Compiling toml v0.2.1
   Compiling libc v0.2.50
   Compiling glob v0.2.11
   Compiling cfg-if v0.1.7
   Compiling bitflags v0.7.0
   Compiling log v0.4.6
   Compiling metadeps v1.1.2
   Compiling cmake v0.1.35
   Compiling zmq-sys v0.9.0 (C:\Users\me\Documents\Code\zmq\rust-zmq-oblique\zmq-sys)
   Compiling zmq v0.9.0 (C:\Users\me\Documents\Code\zmq\rust-zmq-oblique)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" 
  "/LIBPATH:C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.12o3ayia9nhh10ck.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.155eg0ivvqp2mutp.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1cdy22vls1yyb76b.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1j0zugbeb6jitx1v.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1lalou4fkcnaof5a.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1n4vamiheiogcfwj.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1vlvow2ufrnd1z5f.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1ydpiaat0p6t0298.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.22jydi5sluc1xlfo.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.28wmpcw7q8zpqc48.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.29q17rupwuwe3x88.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.2brg1nlypw5ix3t.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.2j1ni91fjuuwp0nr.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.2kzv4s34itq8oj10.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.2lu3dolcj0kh0kfd.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.2xhyy55kqcn1j7w7.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.3dvu0olsvif5479x.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.47gyksltkiactgpc.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.47rivdmigpm0jl6x.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.48hjqo6dhlvpkfut.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.4nueqbbt0lf6uoa7.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.4t38g00p87yce7id.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.563dbr7v8i6intnj.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.56ml527k35lfqb13.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.5f49loa6wlsv3g8o.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.5g3x21g1luegsnyp.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.6pja8lropked6x6.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.9wyioqrxn33k7s1.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.b3jhf1tul77ml20.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.f9mow7ikicexecy.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.hghfhonpxjutb65.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.kjg3zzq4vb0gqr9.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.r5q0a58gli79yc2.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.xiutra319iouez9.rcgu.o" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.y3mouaru42ybesw.rcgu.o" 
  "/OUT:C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.exe" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\build\\zmq-66a861f99677e6f3\\build_script_build-66a861f99677e6f3.1x433sum4zshh0hd.rcgu.o" 
  "/OPT:REF,NOICF" "/DEBUG" "/NATVIS:C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" 
  "/NATVIS:C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" 
  "/NATVIS:C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" 
  "/LIBPATH:C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\deps" 
  "/LIBPATH:C:\\Users\\me\\CMakeBuilds\\97da22d4-c402-2733-9a95-d472ad265e4d\\install\\x64-Release\\lib" 
  "/LIBPATH:C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\deps\\libzmq_sys-30fcbb6f71d66d1b.rlib" 
  "C:\\Users\\me\\Documents\\Code\\zmq\\rust-zmq-oblique\\target\\debug\\deps\\liblibc-87d062f1c0297539.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-eac22bdd33861df1.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-bd033cefe9225fc7.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-9c763a9039daafe7.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-b78aa403ab20ed15.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-9ce0d2c678ca4d7e.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-f94457de73e50aed.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-093f258726e3d316.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-e93a1be54a7dcb84.rlib" 
  "C:\\Users\\me\\.rustup\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-f6363f8aaee883c4.rlib" "zmq.lib" 
  "advapi32.lib" "ws2_32.lib" "userenv.lib" "msvcrt.lib"
  = note: build_script_build-66a861f99677e6f3.47rivdmigpm0jl6x.rcgu.o : error LNK2019: unresolved external symbol __imp_zmq_has referenced in function _ZN18build_script_build4main17h46d2c95a282bdf00E
          C:\Users\me\Documents\Code\zmq\rust-zmq-oblique\target\debug\build\zmq-66a861f99677e6f3\build_script_build-66a861f99677e6f3.exe : fatal error LNK1120: 1 unresolved externals

error: aborting due to previous error

error: Could not compile `zmq`.

To learn more, run the command again with --verbose.

C:\Users\me\Documents\Code\zmq\rust-zmq-oblique>
oblique commented 5 years ago

To make zmq-sys be build automatically you need to enable static-libzmq feature.

Use the following in your Cargo.toml:

zmq = { git = "https://github.com/oblique/rust-zmq", branch = "build-zmq", features = ["static-libzmq"] }
hansieodendaal commented 5 years ago

Hi @oblique, thank you for the response. I added the line to Cargo.toml (here), but still get the same error.

oblique commented 5 years ago

You used rust-zmq's Cargo.toml. The line I gave above you need to put in Cargo.toml of your project and under [dependencies] section.

hansieodendaal commented 5 years ago

Hi @oblique, thank you for the response. I do not have a separate project, I am only trying to build rust-zmq, which gives the linker error. (I will remove that line from Cargo.toml)

oblique commented 5 years ago

In that case just checkout to build-zmq branch and do:

cargo build --features static-libzmq
hansieodendaal commented 5 years ago

Perfect, this worked, thanks!

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Code\zmq\rust-zmq-oblique>cargo build --features static-libzmq
   Compiling cc v1.0.31
   Compiling toml v0.2.1
   Compiling pkg-config v0.3.14
   Compiling error-chain v0.10.0
   Compiling libc v0.2.50
   Compiling glob v0.2.11
   Compiling cfg-if v0.1.7
   Compiling bitflags v0.7.0
   Compiling log v0.4.6
   Compiling metadeps v1.1.2
   Compiling cmake v0.1.35
   Compiling zmq-sys v0.9.0 (C:\Code\zmq\rust-zmq-oblique\zmq-sys)
   Compiling zmq v0.9.0 (C:\Code\zmq\rust-zmq-oblique)
    Finished dev [unoptimized + debuginfo] target(s) in 3m 05s

C:\Code\zmq\rust-zmq-oblique>
rotty commented 5 years ago

Regarding the alternative to this PR, i.e., providing a libzmq-src crate, see also issue #257.

jean-airoldie commented 5 years ago

Regarding the LGPL license since we build from source there is no need to open source the bynaries from my understanding. Indeed the source code would be availlable in the target/ directory itself. And one could choose to link against a different libzmq library.

rotty commented 5 years ago

Regarding the LGPL license since we build from source there is no need to open source the bynaries from my understanding. Indeed the source code would be availlable in the target/ directory itself. And one could choose to link against a different libzmq library.

I was talking about potential closed-source crates; I might not have made that clear. Statically linking/vendoring should not be a problem for FLOSS crates using licenses which are compatible with the LGPL.

While I don't particularly care for closed-source software, I'd like to keep the possibility for dynamic linking, for these two reasons:

jean-airoldie commented 5 years ago

Gotcha. Anyway good luck enforcing the license on close source software.

oblique commented 5 years ago

I'm closing this since the zeromq-src way is much better.