JuliaInterop / Cxx.jl

The Julia C++ Interface
Other
757 stars 108 forks source link

Can't build Cxx.jl on Linux using gcc8 #413

Open rgcv opened 5 years ago

rgcv commented 5 years ago

Hello,

I'm currently facing a problem when attempting to build Cxx out of the box. BinaryBuilder reports that my platform isn't supported as described by the following error log I've obtained upon attempting to build the package:

julia> Pkg.build("Cxx")
  Building Cxx → `~/.julia/packages/Cxx/8BHMC/deps/build.log`
┌ Error: Error building `Cxx`: 
│ [ Info: Building julia binary build
│ ERROR: LoadError: LoadError: Your platform ("x86_64-pc-linux-gnu", parsed as "x86_64-linux-gnu-gcc8-cxx11") is not supported by this package!
│ Stacktrace:
│  [1] top-level scope at /home/rgcv/.julia/packages/Cxx/8BHMC/deps/build_libcxxffi.jl:28
│  [2] include(::String) at ./client.jl:403
│  [3] top-level scope at /home/rgcv/.julia/packages/Cxx/8BHMC/deps/build.jl:53
│  [4] include(::String) at ./client.jl:403
│  [5] top-level scope at none:0
│ in expression starting at /home/rgcv/.julia/packages/Cxx/8BHMC/deps/build_libcxxffi.jl:24
│ in expression starting at /home/rgcv/.julia/packages/Cxx/8BHMC/deps/build.jl:40
│ writing path.jl file
│ Tuning for julia installation at /usr/bin with sources possibly at /usr/bin/../..
└ @ Pkg.Operations /build/julia/src/julia-1.1.0/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075

This more than makes sense since there isn't a binary for my platform. However, at the time of writing, there is one for gcc 7. I've attempted to install gcc 7 in order to somehow counteract this issue, but I ended up with the same error log.

Given this situation, I was wondering if there is an actual way around this predicament or if a binary for a platform using gcc 8 must be provided in order to use Cxx. If the latter's the case, will such a binary be provided?

Additional information:

ararslan commented 5 years ago

@Gnimuc, can you add more GCC versions in CxxBuilder, or was there a reason you did 7 only?

rgcv commented 5 years ago

Just a quick update on this: I managed to build libcxxffi from source using gcc 8. I'm in the process of giving it a quick test run.

Gnimuc commented 5 years ago

Hi @rgcv, it looks like you're using Julia built from source. The official released Julia is built using gcc7, that's what BinaryProvider complained about.

Given this situation, I was wondering if there is an actual way around this predicament or if a binary for a platform using gcc 8 must be provided in order to use Cxx.

A workaround is to remove compiler_abi=CompilerABI(:gcc7) in this line. https://github.com/JuliaInterop/Cxx.jl/blob/47f5215412de63158cdbff68b53b6b620460dba0/deps/build_libcxxffi.jl#L15

This might not work if there could be incompatibility issues between gcc7 and gcc8.

can you add more GCC versions in CxxBuilder, or was there a reason you did 7 only?

libcxxffi needs to be linked with libjulia, but the official released Julia binary is built using gcc7 by default. The ultimate solution would be JuliaBuilder and https://github.com/JuliaLang/julia/issues/27740.

rgcv commented 5 years ago

Hello @Gnimuc,

A workaround is to remove compiler_abi=CompilerABI(:gcc7) in this line.

https://github.com/JuliaInterop/Cxx.jl/blob/47f5215412de63158cdbff68b53b6b620460dba0/deps/build_libcxxffi.jl#L15

Worked wonderfully, package built without a hitch! No warnings, errors, nothing. I was previously trying to build from source, and managed to build the tarball, but hit a wall when I found that loading the package would result in missing references to functions (some name-mangled function in LLVM), later hitting a Segmentation Fault as a consequence, I imagine. I definitely must've goofed somewhere when hacking the julia build files.

This might not work if there could be incompatibility issues between gcc7 and gcc8.

I didn't profusely test it, but I managed to cover a pretty much all the functionality exposed in the README's examples. Looks apparently functional :+1: .

libcxxffi needs to be linked with libjulia, but the official released Julia binary is built using gcc7 by default. The ultimate solution would be JuliaBuilder and JuliaLang/julia#27740.

I hit that issue in past travels as I've been toying around with CxxWrap.jl as well, trying to figure out which best suits my needs.

JuliaBuilder seems to work well for CxxWrap.jl, would integrating it in Cxx.jl's build process be too much of a pain? What would be a good reason (or the reason) not to rely on it as is instead of using the official binaries?

Gnimuc commented 5 years ago

JuliaBuilder is not fully functional for now. Those releases are manually-uploaded Julia tarballs which are exactly the same as those in the official download page.

Currently, libcxxffi binaries are built locally on my machine with the script in this repo and then manually uploaded. It's not like other BB2 projects that build binaries on Travis CI. The reason is again that JuliaBuilder doesn't provide new releases after Julia 1.0.0. I opened an issue a while ago for tracking the status.

Cxx.jl allows users to write wrapper code in pure Julia, which means it needs to parse the C++ code and emit correct("Julia-compatible") LLVM IR code using LLVM/Clang that is compatible with the one that shipped with Julia. Unfortunately, Julia only ships LLVM in its official releases, so we need to find a way to get Clang. That's where LLVMBuilder comes in. However, the official Julia releases did not use LLVMBuilder until a recent PR, so there's still certain incompatibility between LLVMBuilder and the official Julia pre-1.2 releases. CxxWrap.jl does not suffer the dependency issues that Cxx.jl does, so its package status is more stable between Julia releases.

rgcv commented 5 years ago

Alright, makes perfect sense, as far as I can understand what is being said, which is a fair amount, considerably enough.

Thank you for the comprehensive and snappy feedback and help with the issue. As far as the issue's subject's concerned, the workaround described above promptly fixes the problem.