Skip to content

Commit

Permalink
Merge pull request #29 from JuliaGeometry/master
Browse files Browse the repository at this point in the history
use binarybuilder/provider cross compilation
  • Loading branch information
maxvoxel8 authored Jul 10, 2018
2 parents 1bf969d + f9f50f8 commit 71aa1b6
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 5,374 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ test/config
*.exp
*.o
*.so
deps/usr
deps/deps.jl
38 changes: 16 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
sudo: required
install:
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
g++ --version
fi

julia:
- 0.5
- 0.6
- nightly
- 0.7

matrix:
allow_failures:
- julia: 0.7

notifications:
email: false
# uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Clipper"); Pkg.test("Clipper"; coverage=true)'
sudo: false
=======
git:
depth: 99999999
## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- julia: nightly
4 changes: 2 additions & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@windows WinRPM
julia 0.5
julia 0.6
BinaryProvider
19 changes: 12 additions & 7 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

## uncomment the following lines to allow failures on nightly julia
## (tests will run but not make your overall status red)
matrix:
allow_failures:
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
Expand All @@ -15,13 +20,13 @@ notifications:
on_build_failure: false
on_build_status_changed: false

os: Visual Studio 2015
platform:
- x64

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
- call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x64
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
Expand All @@ -36,4 +41,4 @@ build_script:
Pkg.clone(pwd(), \"Clipper\"); Pkg.build(\"Clipper\")"

test_script:
- C:\projects\julia\bin\julia --check-bounds=yes -e "Pkg.test(\"Clipper\")"
- C:\projects\julia\bin\julia -e "Pkg.test(\"Clipper\")"
74 changes: 40 additions & 34 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
#! /usr/bin/env julia
using BinaryProvider # requires BinaryProvider 0.3.0 or later

path = joinpath(dirname(@__FILE__), "..", "src")
# 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, String["cclipper"], :cclipper),
]

if is_windows()
# if success(`where cl.exe`)
# info("Compiling with cl.exe")
# run(`cl.exe /D_USRDLL /D_WINDLL /EHsc /Fo$(path) $(path)cclipper.cpp $(path)clipper.cpp /MT /link /DLL /OUT:$(path)cclipper.dll`)
# else
import WinRPM
info("Compiling with WinRPM gcc-c++")
WinRPM.install("gcc-c++"; yes = true)
WinRPM.install("gcc"; yes = true)
WinRPM.install("headers"; yes = true)
WinRPM.install("winpthreads-devel"; yes = true)
# Download binaries from hosted location
bin_prefix = "https://github.com/SimonDanisch/ClipperBuilder/releases/download/v1.0.0"

gpp = Pkg.dir("WinRPM","deps","usr","x86_64-w64-mingw32","sys-root","mingw","bin","g++")
RPMbindir = Pkg.dir("WinRPM","deps","usr","x86_64-w64-mingw32","sys-root","mingw","bin")
incdir = Pkg.dir("WinRPM","deps","usr","x86_64-w64-mingw32","sys-root","mingw","include")
# Listing of files generated by BinaryBuilder:
download_info = Dict(
Linux(:aarch64, :glibc) => ("$bin_prefix/Clipper.v1.0.0.aarch64-linux-gnu.tar.gz", "8257bdcb54563f2effbd1ea484be39437e245a01bd1badb93706625599019581"),
Linux(:aarch64, :musl) => ("$bin_prefix/Clipper.v1.0.0.aarch64-linux-musl.tar.gz", "2967e0e6a400053f01fcaf6ea3c214342c346c627ef1d11343088d8dae8211d2"),
Linux(:armv7l, :glibc, :eabihf) => ("$bin_prefix/Clipper.v1.0.0.arm-linux-gnueabihf.tar.gz", "a03c2e0455af89eeefcd4f5ca22ed72db47ee5718c7b815a347221ab2692da2a"),
Linux(:armv7l, :musl, :eabihf) => ("$bin_prefix/Clipper.v1.0.0.arm-linux-musleabihf.tar.gz", "49d14834c9817e4d877bd6facd33bf242f394e82af5a6c711c063e4aa225131e"),
Linux(:i686, :glibc) => ("$bin_prefix/Clipper.v1.0.0.i686-linux-gnu.tar.gz", "8bbdf10ba64b039d5172b5362f3048fec329b048c21e385a2c8feea78fc62c11"),
Linux(:i686, :musl) => ("$bin_prefix/Clipper.v1.0.0.i686-linux-musl.tar.gz", "bf1e3a62bbf6cc8ea871b242d89dfa12477313a7ad990c1a930f83e18dd075f5"),
Windows(:i686) => ("$bin_prefix/Clipper.v1.0.0.i686-w64-mingw32.tar.gz", "320ac5a275f33943421df9123e74344c59eeb20bc0c89de73501a83924be1453"),
Linux(:powerpc64le, :glibc) => ("$bin_prefix/Clipper.v1.0.0.powerpc64le-linux-gnu.tar.gz", "ee312d90ceb0ec87092a502014d1d3e56d735186fa728c3cc77088145d6f9ce9"),
MacOS(:x86_64) => ("$bin_prefix/Clipper.v1.0.0.x86_64-apple-darwin14.tar.gz", "0ddc80a5a9d8be456facc92fadddde6755d1aa9d5d9cea8095f69dcc6adec1ba"),
Linux(:x86_64, :glibc) => ("$bin_prefix/Clipper.v1.0.0.x86_64-linux-gnu.tar.gz", "0883bcac9afb68d2ffb822453727ad9fe309a088f9192dd13c26654100d39c57"),
Linux(:x86_64, :musl) => ("$bin_prefix/Clipper.v1.0.0.x86_64-linux-musl.tar.gz", "fd61e7319a79d6a9d32d1c7ad72302d313ca20756472a21a7bae8c41e942d01a"),
FreeBSD(:x86_64) => ("$bin_prefix/Clipper.v1.0.0.x86_64-unknown-freebsd11.1.tar.gz", "39a010ff1d9007641524c276ca9c58ddf68a9f9b4bde98b6fda84950593d385a"),
Windows(:x86_64) => ("$bin_prefix/Clipper.v1.0.0.x86_64-w64-mingw32.tar.gz", "214b2ab0646e2b7fc33376480823a19481a88200a4463a240bb2a747b593a3fd"),
)

push!(Base.Libdl.DL_LOAD_PATH, RPMbindir)
ENV["PATH"] = ENV["PATH"] * ";" * RPMbindir
if success(`$gpp --version`)
cd(path) do
run(`$gpp -c -fPIC -std=c++11 clipper.cpp cclipper.cpp -I $incdir`)
run(`$gpp -shared -o cclipper.dll clipper.o cclipper.o`)
end
else
error("no windows c++ compiler (cl.exe) found, and WinRPM with g++ is failing as well.")
end
# end
end

if is_unix()
cd(path) do
# Note: on Mac OS X, g++ is aliased to clang++.
run(`g++ -c -fPIC -std=c++11 clipper.cpp cclipper.cpp`)
run(`g++ -shared -o cclipper.so clipper.o cclipper.o`)
# Install unsatisfied or updated dependencies:
unsatisfied = any(!satisfied(p; verbose=verbose) for p in products)
if haskey(download_info, platform_key())
url, tarball_hash = download_info[platform_key()]
if unsatisfied || !isinstalled(url, tarball_hash; prefix=prefix)
# Download and install binaries
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
end
elseif unsatisfied
# If we don't have a BinaryProvider-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 $(triplet(platform_key())) is not supported by this package!")
end

# Write out a deps.jl file that will contain mappings for our products
write_deps_file(joinpath(@__DIR__, "deps.jl"), products)
77 changes: 41 additions & 36 deletions src/Clipper.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
__precompile__()
module Clipper

const depsfile = joinpath(@__DIR__, "..", "deps", "deps.jl")

if isfile(depsfile)
include(depsfile)
else
error("Clipper not build correctly. Please run Pkg.build(\"Clipper\")")
end

function __init__()
check_deps()
end


export PolyType, PolyTypeSubject, PolyTypeClip,
ClipType, ClipTypeIntersection, ClipTypeUnion, ClipTypeDifference, ClipTypeXor,
PolyFillType, PolyFillTypeEvenOdd, PolyFillTypeNonZero, PolyFillTypePositive, PolyFillTypeNegative,
Expand All @@ -19,43 +33,36 @@ module Clipper

@enum EndType EndTypeClosedPolygon=0 EndTypeClosedLine=1 EndTypeOpenSquare=2 EndTypeOpenRound=3 EndTypeOpenButt=4

@static if is_windows()
const library_path = joinpath(dirname(@__FILE__), "cclipper.dll")
end

@static if is_unix()
const library_path = joinpath(dirname(@__FILE__), "cclipper.so")
end

immutable IntPoint
X::Int64
Y::Int64
end

type PolyNode{T}
mutable struct PolyNode{T}
contour::Vector{T}
hole::Bool
open::Bool
children::Vector{PolyNode{T}}
parent::PolyNode{T}
(::Type{PolyNode{T}}){T}(a,b,c) = new{T}(a,b,c)
function (::Type{PolyNode{T}}){T}(a,b,c,d)
PolyNode{T}(a,b,c) where {T} = new{T}(a,b,c)
function PolyNode{T}(a,b,c,d) where T
p = new{T}(a,b,c,d)
p.parent = p
return p
end
(::Type{PolyNode{T}}){T}(a,b,c,d,e) = new{T}(a,b,c,d,e)
PolyNode{T}(a,b,c,d,e) where {T} = new{T}(a,b,c,d,e)
end

Base.convert{T}(::Type{PolyNode{T}}, x::PolyNode{T}) = x
function Base.convert{S,T}(::Type{PolyNode{S}}, x::PolyNode{T})
Base.convert(::Type{PolyNode{T}}, x::PolyNode{T}) where {T} = x
function Base.convert(::Type{PolyNode{S}}, x::PolyNode{T}) where {S,T}
parent(x) !== x && error("must convert a top-level PolyNode (i.e. a PolyTree).")

pn = PolyNode{S}(convert(Vector{S}, contour(x)), ishole(x), isopen(x))
pn.children = [PolyNode(y,pn) for y in children(x)]
pn.parent = pn
end
function PolyNode{S}(x::PolyNode, parent::PolyNode{S})
function PolyNode(x::PolyNode, parent::PolyNode{S}) where S
pn = PolyNode{S}(contour(x), ishole(x), isopen(x))
pn.children = [PolyNode(y,pn) for y in children(x)]
pn.parent = parent
Expand Down Expand Up @@ -118,19 +125,19 @@ module Clipper
# Static functions
#==============================================================#
function orientation(path::Vector{IntPoint})
ccall((:orientation, library_path), Cuchar, (Ptr{IntPoint}, Csize_t),
ccall((:orientation, cclipper), Cuchar, (Ptr{IntPoint}, Csize_t),
path,
length(path)) == 1 ? true : false
end

function area(path::Vector{IntPoint})
ccall((:area, library_path), Float64, (Ptr{IntPoint}, Csize_t),
ccall((:area, cclipper), Float64, (Ptr{IntPoint}, Csize_t),
path,
length(path))
end

function pointinpolygon(pt::IntPoint, path::Vector{IntPoint})
ccall((:pointinpolygon, library_path), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
ccall((:pointinpolygon, cclipper), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
pt,
path,
length(path))
Expand All @@ -139,19 +146,18 @@ module Clipper
#==============================================================#
# Clipper object
#==============================================================#
type Clip
mutable struct Clip
clipper_ptr::Ptr{Void}

function Clip()
clipper = new(ccall((:get_clipper, library_path), Ptr{Void}, ()))
finalizer(clipper, c -> ccall((:delete_clipper, library_path), Void, (Ptr{Void},), c.clipper_ptr))

clipper = new(ccall((:get_clipper, cclipper), Ptr{Void}, ()))
finalizer(clipper, c -> ccall((:delete_clipper, cclipper), Void, (Ptr{Void},), c.clipper_ptr))
clipper
end
end

function add_path!(c::Clip, path::Vector{IntPoint}, polyType::PolyType, closed::Bool)
ccall((:add_path, library_path), Cuchar, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cuchar),
ccall((:add_path, cclipper), Cuchar, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cuchar),
c.clipper_ptr,
path,
length(path),
Expand All @@ -165,7 +171,7 @@ module Clipper
push!(lengths, length(path))
end

ccall((:add_paths, library_path), Cuchar, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cuchar),
ccall((:add_paths, cclipper), Cuchar, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cuchar),
c.clipper_ptr,
paths,
lengths,
Expand All @@ -177,7 +183,7 @@ module Clipper
function execute(c::Clip, clipType::ClipType, subjFillType::PolyFillType, clipFillType::PolyFillType)
polys = Vector{Vector{IntPoint}}()

result = ccall((:execute, library_path), Cuchar, (Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}),
result = ccall((:execute, cclipper), Cuchar, (Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}),
c.clipper_ptr,
Int(clipType),
Int(subjFillType),
Expand All @@ -191,7 +197,7 @@ module Clipper
function execute_pt(c::Clip, clipType::ClipType, subjFillType::PolyFillType, clipFillType::PolyFillType)
pt = PolyNode{IntPoint}(IntPoint[], false, false, PolyNode{IntPoint}[])

result = ccall((:execute_pt, library_path), Cuchar,
result = ccall((:execute_pt, cclipper), Cuchar,
(Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}, Ptr{Void}),
c.clipper_ptr,
Int(clipType),
Expand All @@ -205,36 +211,36 @@ module Clipper
end

function clear!(c::Clip)
ccall((:clear, library_path), Void, (Ptr{Void},), c.clipper_ptr)
ccall((:clear, cclipper), Void, (Ptr{Void},), c.clipper_ptr)
end

type IntRect
mutable struct IntRect
left::Int64
top::Int64
right::Int64
bottom::Int64
end

function get_bounds(c::Clip)
ccall((:get_bounds, library_path), IntRect, (Ptr{Void}, ), c.clipper_ptr)
ccall((:get_bounds, cclipper), IntRect, (Ptr{Void}, ), c.clipper_ptr)
end

#==============================================================#
# ClipperOffset object
#==============================================================#
type ClipperOffset
mutable struct ClipperOffset
clipper_ptr::Ptr{Void}

function ClipperOffset(miterLimit::Float64 = 2.0, roundPrecision::Float64 = 0.25)
clipper = new(ccall((:get_clipper_offset, library_path), Ptr{Void}, (Cdouble, Cdouble), miterLimit, roundPrecision))
finalizer(clipper, c -> ccall((:delete_clipper_offset, library_path), Void, (Ptr{Void},), c.clipper_ptr))
clipper = new(ccall((:get_clipper_offset, cclipper), Ptr{Void}, (Cdouble, Cdouble), miterLimit, roundPrecision))
finalizer(clipper, c -> ccall((:delete_clipper_offset, cclipper), Void, (Ptr{Void},), c.clipper_ptr))

clipper
end
end

function add_path!(c::ClipperOffset, path::Vector{IntPoint}, joinType::JoinType, endType::EndType)
ccall((:add_offset_path, library_path), Void, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cint),
ccall((:add_offset_path, cclipper), Void, (Ptr{Void}, Ptr{IntPoint}, Csize_t, Cint, Cint),
c.clipper_ptr,
path,
length(path),
Expand All @@ -248,7 +254,7 @@ module Clipper
push!(lengths, length(path))
end

ccall((:add_offset_paths, library_path), Void, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cint),
ccall((:add_offset_paths, cclipper), Void, (Ptr{Void}, Ptr{Ptr{IntPoint}}, Ptr{Csize_t}, Csize_t, Cint, Cint),
c.clipper_ptr,
paths,
lengths,
Expand All @@ -258,13 +264,12 @@ module Clipper
end

function clear!(c::ClipperOffset)
ccall((:clear_offset, library_path), Void, (Ptr{Void},), c.clipper_ptr)
ccall((:clear_offset, cclipper), Void, (Ptr{Void},), c.clipper_ptr)
end

function execute(c::ClipperOffset, delta::Float64)
polys = Vector{Vector{IntPoint}}()

result = ccall((:execute_offset, library_path), Void, (Ptr{Void}, Cdouble, Any, Ptr{Void}),
result = ccall((:execute_offset, cclipper), Void, (Ptr{Void}, Cdouble, Any, Ptr{Void}),
c.clipper_ptr,
delta,
polys,
Expand Down
Loading

0 comments on commit 71aa1b6

Please sign in to comment.