JuliaInterop / libcxxwrap-julia

C++ library for backing CxxWrap.jl
Other
79 stars 43 forks source link

How are we supposed to build a project? #60

Open nlw0 opened 4 years ago

nlw0 commented 4 years ago

How exactly am I supposed to build a project using this library, only installing CxxWrap from Pkg?

So far I have been installing CxxWrap, then libcxxwrap from the repo, and then I also buid my own libcxxwrap just for the sake of linking it. Of course this cannot be the proper way.

I am not interested at all in using any special versions of libcxxwrap. I just want to be a user of this library, and link to whatever the latest release of the CxxWrap package requires.

How do I find out what is the directory I need to feed to cmake via JlCxx_DIR=...?

Right now I think I have only installed CxxWrap, and then I try to build my project using cmake .. -DJlCxx_DIR=$HOME/.julia/packages/CxxWrap/lDNAy/deps/usr/lib/cmake/JlCxx. Everything seems to go well, but then I try using my package and I hit some god-awful runtime error. Right now I'm getting

undefined symbol: _ZN5jlcxx19FunctionWrapperBase19set_pointer_indicesEv

which looks to me like I'm linking to the wrong library. What am I doing wrong?

jstrube commented 4 years ago

The easiest way is to use a BinaryBuilder script. For example, here is what I do for development: I have a build script in my .ci folder, e.g. https://github.com/jstrube/LCIO_Julia_Wrapper/blob/main/.ci/build_tarballs.jl You can see that this just defines a dependency on libcxxwrap. It should use the same version that is already downloaded by CxxWrap.

The script part defines how you build your library. What I do to test this is then to run julia LCIO_Julia_Wrapper/.ci/build_tarballs.jl --deploy=jstrube/LCIO_Julia_Wrapper_jll.jl --register. This builds the project, packs it into an artifact, puts a copy in my github repo, and registers it in ~/.julia/dev. From there my julia project can just pick it up (provided the versions in Project.toml of the julia project match).

barche commented 4 years ago

I am not interested at all in using any special versions of libcxxwrap. I just want to be a user of this library, and link to whatever the latest release of the CxxWrap package requires.

The CxxWrap binaries are built using BinaryBuilder, which means that they are almost always incompatible for linking against using the native development tools on users' machines. The only possible options are to either build libcxxwrap-julia yourself and use Overrides.toml, or use BinaryBuilder even for local development, as suggested by @jstrube (which seems like a pretty nice way, actually, I should try it ;)

cfitz25 commented 3 years ago

How would i go about using the BinaryBuilder to build CxxWrap with this? I read the example @jstrube wrote and it appears id modify that file to produce CxxWrap correct? Im very new to this sorry.

jstrube commented 3 years ago

I usually deal with this in three pieces:

  1. One file on Yggdrasil for the C++ code, i.e. the code that I want to wrap. This creates binary artifacts.
  2. One repository that contains the wrapper code. This code depends only on libcxxwrap-julia and contains only C++ code, no Julia. I write a build script on Yggdrasil that depends on the output of step 1 and in turn creates a new artifact.
  3. One repository containing the Julia package. This depends on the Julia CxxWrap.jl package, and the artifact created in step 2.
barche commented 3 years ago

Another option now is to use Docker, see the first part of the workshop here:

https://live.juliacon.org/talk/NNVQQF