Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade build system to BB2 -- Part 1 #406

Merged
merged 31 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
63d3a42
`dump()` => `print(llvm::errs(), false)`
Gnimuc Dec 3, 2018
1082e5f
`contains` => `occursin`, a upgrading oversight
Gnimuc Dec 3, 2018
a3d0658
Fix REPL mode
Gnimuc Dec 7, 2018
ce470a5
Misc. upgrading oversight
Gnimuc Dec 7, 2018
1f46d4b
Update cxxstr.jl
Gnimuc Dec 14, 2018
b052655
Fix segmentfault
Gnimuc Mar 5, 2019
0371e22
Bump Julia version and update CI
Gnimuc Mar 9, 2019
f6e76e2
Upgrade build system to BB2
Gnimuc Mar 9, 2019
3b08f4e
Workaround for Windows ABI mismatch
Gnimuc Mar 10, 2019
8734893
Fix another Windows glitch
Gnimuc Mar 10, 2019
7a970eb
Safer path separator solutions
Gnimuc Mar 10, 2019
ff9dd89
Fix source file path separator for Windows
Gnimuc Mar 10, 2019
a2ffdb9
Add `__cxa_atexit` as per suggested in #145
Gnimuc Mar 10, 2019
4ab7ed5
Remove meaningless GC preserve
Gnimuc Mar 10, 2019
d693ef8
Only define `__cxa_atexit` on Windows
Gnimuc Mar 13, 2019
fd76838
Try to fix CI on macOS
Gnimuc Mar 13, 2019
ad7d1d4
Update build_libcxxffi.jl
Gnimuc Apr 12, 2019
b22a038
Add missing libname
Gnimuc Apr 11, 2019
39d20ce
Fix signature mismatch
Gnimuc Apr 11, 2019
d8d6e1d
Workaround for building issues on Julia master
Gnimuc Apr 11, 2019
60b39ff
Enable appveyor and update badge links
Gnimuc Apr 11, 2019
6b9616e
Search `xcode_path` in a more robust way
Gnimuc Apr 12, 2019
76fb097
Minor fix
Gnimuc Apr 12, 2019
e3b85fc
Revert `#define C CxxInstance *Cxx`
Gnimuc Apr 12, 2019
2af4969
Add Windows support -- Take 1
Gnimuc Apr 12, 2019
60ca88f
Update `AddressSpace` to be consistent with Julia source
Gnimuc Apr 12, 2019
cf41caa
Drop LLVM6.0.0- backward compatibility
Gnimuc Apr 12, 2019
40d30f6
Add an error message for poor mac users
Gnimuc Apr 22, 2019
aa1560f
Update README.md
Gnimuc Apr 22, 2019
30c692d
Update build_libcxxffi.jl
Gnimuc Apr 23, 2019
c63c748
Update README and warn Windows users
Gnimuc Apr 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
.DS_Store
docs/build
docs/site
deps/build.log
Manifest.toml
73 changes: 13 additions & 60 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,31 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia

os:
- linux
- osx

julia:
- 0.7
- 1.0
- 1.1
- nightly

matrix:
allow_failures:
- julia: nightly
fast_finish: true

notifications:
email: false
sudo: false
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
packages:
- cmake
- cmake-data
- gcc-6
- g++-6
- binutils
- gfortran
- libblas-dev
- liblapack-dev
- libgmp-dev
- libmpfr-dev
cache:
directories:
- $TRAVIS_BUILD_DIR/deps/src
- $TRAVIS_BUILD_DIR/deps/build
- ~/usr
before_cache:
- rm $TRAVIS_BUILD_DIR/deps/build/bootstrap.o
- rm -rf $TRAVIS_BUILD_DIR/deps/usr
before_script:
- |
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
export CXX="g++-6" CC="gcc-6"
export PATH="$HOME/usr/bin:$PATH"
else
export CXX="clang++" CC="clang"
fi
- |
if [ "$TRAVIS_OS_NAME" = "linux" ] && [ ! -f $HOME/usr/bin/ld ]; then
wget https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz
tar xzf binutils-2.27.tar.gz
(cd binutils-2.27 && ./configure --prefix=$HOME/usr && make && make install)
fi
- mkdir -p $TRAVIS_BUILD_DIR/../Cxx-cache && cp -R $TRAVIS_BUILD_DIR $TRAVIS_BUILD_DIR/../Cxx-cache
- julia -e 'using InteractiveUtils; versioninfo()'
script:
- julia --project=. -e 'using Pkg; Pkg.instantiate()'
- mv $TRAVIS_BUILD_DIR/../Cxx-cache/deps/src $TRAVIS_BUILD_DIR/deps/src || true
- mv $TRAVIS_BUILD_DIR/../Cxx-cache/deps/build $TRAVIS_BUILD_DIR/deps/build || true
- |
if [ ! -f $HOME/early_abort ]; then
PREBUILT_CI_BINARIES=1 julia --project=. -e 'using Pkg; Pkg.build()' || false
fi
- |
if [ ! -f $HOME/early_abort ]; then
julia --project=. -e 'Pkg.test(coverage=true)' || false
fi
after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

jobs:
include:
- stage: "Documentation"
julia: 1.0
julia: 1.1
os: linux
script:
- julia --project=docs/ -e 'using Pkg; Pkg.instantiate(); Pkg.develop(PackageSpec(path=pwd()))'
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
Pkg.build(); Pkg.instantiate()'
- julia --project=docs/ docs/make.jl
after_success: skip

after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name = "Cxx"
uuid = "a0b5b9ef-44b7-5148-a2d1-f6db19f3c3d2"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

Expand Down
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
## Cxx.jl

[![Build Status](https://travis-ci.org/Keno/Cxx.jl.svg?branch=master)](https://travis-ci.org/Keno/Cxx.jl)
[![codecov.io](http://codecov.io/github/Keno/Cxx.jl/coverage.svg?branch=master)](http://codecov.io/github/Keno/Cxx.jl?branch=master)
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://Keno.github.io/Cxx.jl/latest)
[![Build Status](https://travis-ci.org/JuliaInterop/Cxx.jl.svg?branch=master)](https://travis-ci.org/JuliaInterop/Cxx.jl)
[![Build status](https://ci.appveyor.com/api/projects/status/uimv2b4shsb5ndcj/branch/master?svg=true)](https://ci.appveyor.com/project/JuliaInterop/cxx-jl/branch/master)
[![codecov](https://codecov.io/gh/JuliaInterop/Cxx.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaInterop/Cxx.jl)
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://JuliaInterop.github.io/Cxx.jl/stable)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaInterop.github.io/Cxx.jl/dev)

The Julia C++ Foreign Function Interface (FFI) and REPL.

![REPL Screenshot](docs/screenshot.png "C++ REPL Screenshot")


### Installation
Now, this package provides an out-of-box installation experience on all 64-bit ["Tier 1"](https://github.com/JuliaLang/julia#currently-supported-platforms) platforms for Julia 1.1.
```
pkg> add Cxx
```
Note that Windows support is still in its early stage, so feel free to submit feedback in the issue tracker.

### Build from source
#### Build requirements

In addition to the [system requirements](https://github.com/JuliaLang/julia#required-build-tools-and-external-libraries) to build julia itself, the following are required:
Expand All @@ -20,10 +28,9 @@ In addition to the [system requirements](https://github.com/JuliaLang/julia#requ

#### Building Cxx

Launch julia (version 1.0 or later), and in the terminal type
Launch Julia (version 1.0 or later), and in the terminal type
```julia
using Pkg
Pkg.add("Cxx")
pkg> build Cxx
```

### How it works
Expand All @@ -34,10 +41,10 @@ The main interface provided by Cxx.jl is the @cxx macro. It supports two main us
@cxx mynamespace::func(args...)
- Membercall (where m is a CppPtr, CppRef or CppValue)
@cxx m->foo(args...)

To embed C++ functions in Julia, there are two main approaches:

```julia
```julia
# Using @cxx (e.g.):
cxx""" void cppfunction(args){ . . .} """ => @cxx cppfunction(args)

Expand All @@ -51,7 +58,7 @@ This package contains an experimental C++ REPL feature. Using the package
will automatically add a new pane to your REPL that is accessible by pressing the
`<` key.

### **Using Cxx.jl:**
### **Using Cxx.jl:**

#### Example 1: Embedding a simple C++ function in Julia

Expand All @@ -73,7 +80,7 @@ julia> cxx"""
# Convert C++ to Julia function
julia> julia_function() = @cxx mycppfunction()
julia_function (generic function with 1 method)

# Run the function
julia> julia_function()
The number is 52
Expand All @@ -84,15 +91,15 @@ The number is 52
```julia
julia> jnum = 10
10

julia> cxx"""
void printme(int x) {
std::cout << x << std::endl;
}
"""

julia> @cxx printme(jnum)
10
10
```

#### Example 3: Pass strings from Julia to C++
Expand All @@ -107,7 +114,7 @@ julia> cxx"""
"""

julia> @cxx printme(pointer("John"))
John
John
```

#### Example 4: Pass a Julia expression to C++
Expand Down Expand Up @@ -161,7 +168,7 @@ CppEnum{Symbol("Klassy::Foo")}(1)
julia> using Cxx
julia> cxx"""#include <iostream>
class Hello
{
{
public:
void hello_world(const char *now){
std::string snow = now;
Expand Down Expand Up @@ -215,7 +222,7 @@ float* ArrayMaker::fillArr() {
for (int i=0; i < iNumber; i++) {
fArr[i] = fNumber;
fNumber *= 2;
}
}
return fArr;
}
```
Expand All @@ -234,13 +241,13 @@ julia> using Cxx
julia> const path_to_lib = pwd()
julia> addHeaderDir(path_to_lib, kind=C_System)
julia> Libdl.dlopen(path_to_lib * "/libArrayMaker.so", Libdl.RTLD_GLOBAL)
Ptr{Void} @0x000000000728e6d0
Ptr{Cvoid} @0x000000000728e6d0
julia> cxxinclude("ArrayMaker.h")

# Creating class object
julia> maker = @cxxnew ArrayMaker(5, 2.0)
Got arguments: 5, and 2
Cxx.CppPtr{Cxx.CppValue{Cxx.CppBaseType{:ArrayMaker},(false,false,false)},(false,false,false)}(Ptr{Void} @0x00000000060ab570)
Cxx.CppPtr{Cxx.CppValue{Cxx.CppBaseType{:ArrayMaker},(false,false,false)},(false,false,false)}(Ptr{Cvoid} @0x00000000060ab570)

julia> arr = @cxx maker->fillArr()
Filling the array
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.7
julia 1.1
BinaryProvider 0.3.0
43 changes: 43 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
environment:
matrix:
- julia_version: 1.1
- julia_version: nightly

platform:
# - x86 # 32-bit
- x64 # 64-bit

# # Uncomment the following lines to allow failures on nightly julia
# # (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia_version: nightly

# branches:
# only:
# - master
# - /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
# Install Julia
- ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1"))

build_script:
- echo "%JL_BUILD_SCRIPT%"
- C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%"

# test_script:
# - echo "%JL_TEST_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%"

# # Uncomment to support code coverage upload. Should only be enabled for packages
# # which would have coverage gaps without running on Windows
# on_success:
# - echo "%JL_CODECOV_SCRIPT%"
# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%"
19 changes: 12 additions & 7 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ export BASE_JULIA_BIN
const BASE_JULIA_SRC=$(sprint(show, BASE_JULIA_SRC))
export BASE_JULIA_SRC
"""
f = open(joinpath(dirname(@__FILE__),"path.jl"), "w")
write(f, s)
close(f)

println("Tuning for julia installation at $BASE_JULIA_BIN with sources possibly at $BASE_JULIA_SRC")

# Try to autodetect C++ ABI in use
llvm_path = (Sys.isapple() && VersionNumber(Base.libllvm_version) >= v"3.8") ? "libLLVM" : "libLLVM-$(Base.libllvm_version)"
llvm_path = Sys.iswindows() ? "LLVM" :
(Sys.isapple() && Base.libllvm_version >= v"3.8") ? "libLLVM" : "libLLVM-$(Base.libllvm_version)"

llvm_lib_path = Libdl.dlpath(llvm_path)
old_cxx_abi = findfirst("_ZN4llvm3sys16getProcessTripleEv", String(open(read, llvm_lib_path))) !== nothing
Expand All @@ -43,12 +41,19 @@ if isfile(llvm_config_path)
@info "Building julia source build"
ENV["LLVM_CONFIG"] = llvm_config_path
delete!(ENV,"LLVM_VER")
make = Sys.isbsd() && !Sys.isapple() ? `gmake` : `make`
run(`$make -j$(Sys.CPU_THREADS) -f BuildBootstrap.Makefile BASE_JULIA_BIN=$BASE_JULIA_BIN BASE_JULIA_SRC=$BASE_JULIA_SRC`)
s = s * "\n const IS_BINARYBUILD = false"
else
@info "Building julia binary build"
Sys.iswindows() && @warn "Windows support is still experimental!"
ENV["LLVM_VER"] = Base.libllvm_version
ENV["JULIA_BINARY_BUILD"] = "1"
ENV["PATH"] = string(JULIA_HOME,":",ENV["PATH"])
ENV["PATH"] = string(BASE_JULIA_BIN,":",ENV["PATH"])
include("build_libcxxffi.jl")
s = s * "\n const IS_BINARYBUILD = true"
end

make = Sys.isbsd() && !Sys.isapple() ? `gmake` : `make`
run(`$make -j$(Sys.CPU_THREADS) -f BuildBootstrap.Makefile BASE_JULIA_BIN=$BASE_JULIA_BIN BASE_JULIA_SRC=$BASE_JULIA_SRC`)
f = open(joinpath(dirname(@__FILE__),"path.jl"), "w")
write(f, s)
close(f)
39 changes: 39 additions & 0 deletions deps/build_libcxxffi.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BinaryProvider # requires BinaryProvider 0.3.0 or later

# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS
const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))
products = [
LibraryProduct(prefix, ["libcxxffi"], :libcxxffi),
]

# Download binaries from hosted location
bin_prefix = "https://github.com/JuliaInterop/Cxx.jl/releases/download/libcxxffi-binaries/"

# Listing of files generated by BinaryBuilder:
download_info = Dict(
Linux(:x86_64, libc=:glibc, compiler_abi=CompilerABI(:gcc7)) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-linux-gnu-gcc7.tar.gz", "cc53946f4867d95f543ad112db6a5ce40bbdf9f5b9a8982906a14c1cff5aaced"),
MacOS(:x86_64) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-apple-darwin14-gcc7.tar.gz", "76aa1dfc7ecb97069043ed6e19b685371e04daf92d73201aaf054678e2a11cf1"),
Windows(:x86_64) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-w64-mingw32-gcc7.tar.gz", "9730c0c438e3cfcfc793d05e511b428e01aebf75085bd36582c822e220532790"),
FreeBSD(:x86_64, compiler_abi=CompilerABI(:gcc7)) => ("$bin_prefix/libcxxffi.v0.0.0.x86_64-unknown-freebsd11.1-gcc7.tar.gz", "930df7bf7ecded6936dd9f637787b7eade402c07c0c2b2b49c4e72329d6bd9ef"),
)

# Install unsatisfied or updated dependencies:
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
dl_info = choose_download(download_info, platform_key_abi())
if dl_info === nothing && unsatisfied
# If we don't have a compatible .tar.gz to download, complain.
# Alternatively, you could attempt to install from a separate provider,
# build from source or something even more ambitious here.
error("Your platform (\"$(Sys.MACHINE)\", parsed as \"$(triplet(platform_key_abi()))\") is not supported by this package!")
end

# If we have a download, and we are unsatisfied (or the version we're
# trying to install is not itself installed) then load it up!
if unsatisfied || !isinstalled(dl_info...; prefix=prefix)
# Download and install binaries
install(dl_info...; prefix=prefix, force=true, verbose=verbose, ignore_platform=true)
end

# Write out a deps.jl file that will contain mappings for our products
# write_deps_file(joinpath(@__DIR__, "deps.jl"), products, verbose=verbose)
4 changes: 2 additions & 2 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ John
```julia-repl
julia> cxx"""
void test_print() {
$:(println("\nTo end this test, press any key")::Void);
$:(println("\nTo end this test, press any key")::Cvoid);
}
"""
true
Expand Down Expand Up @@ -200,7 +200,7 @@ julia> const path_to_lib = pwd();
julia> addHeaderDir(path_to_lib, kind=C_System)

julia> Libdl.dlopen(joinpath(path_to_lib, "libarraymaker.so"), Libdl.RTLD_GLOBAL)
Ptr{Void} @0x00007f9dd4556d60
Ptr{Nothing} @0x00007f9dd4556d60

julia> cxxinclude("ArrayMaker.h")

Expand Down
2 changes: 1 addition & 1 deletion docs/src/implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unboxing `x` and `y` if necessary). Afterwards, the resulting call instruction
is inlined.

In this package, however, we use the second form of `llvmcall`, which differs
from the first in that the IR argument is not a string, but a `Ptr{Void}`. In
from the first in that the IR argument is not a string, but a `Ptr{Cvoid}`. In
this case, Julia will skip the wrapping and proceed straight to argument
translation and inlining.

Expand Down
Loading