Skip to content

Commit

Permalink
Merge pull request #4 from JuliaGeometry/sd/binaryprovider
Browse files Browse the repository at this point in the history
use binaryprovider
  • Loading branch information
SimonDanisch authored Jul 5, 2018
2 parents 85e35e7 + eea7cc7 commit f9f50f8
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5,323 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
## Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
os:
- linux
- osx

julia:
- 0.6
- nightly
- 0.7

matrix:
allow_failures:
- julia: 0.7

notifications:
email: false
sudo: false
=======
git:
depth: 99999999
## uncomment the following lines to allow failures on nightly julia
Expand Down
64 changes: 36 additions & 28 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
using BinaryProvider

# This is where all binaries will get installed
const prefix = Prefix(!isempty(ARGS) ? ARGS[1] : joinpath(@__DIR__,"usr"))

# Instantiate products here. Examples:
clipper_lib = LibraryProduct(prefix, "cclipper")

# Assign products to `products`:
products = [clipper_lib]
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, String["cclipper"], :cclipper),
]

# Download binaries from hosted location
bin_prefix = "https://github.com/SimonDanisch/ClipperBuilder/raw/v0.1.0/products"
bin_prefix = "https://github.com/SimonDanisch/ClipperBuilder/releases/download/v1.0.0"

# Listing of files generated by BinaryBuilder:
download_info = Dict(
BinaryProvider.Linux(:aarch64, :glibc) => ("$bin_prefix/Clipper.aarch64-linux-gnu.tar.gz", "d1247e882a03ab96e6c34f2119ed1f4b513e25d30b3605feab38f61360353272"),
BinaryProvider.Linux(:armv7l, :glibc) => ("$bin_prefix/Clipper.arm-linux-gnueabihf.tar.gz", "6d9912c43e02a51f727192724d08b590c8b0033bb29494e6e47a779f4be522d1"),
BinaryProvider.Linux(:i686, :glibc) => ("$bin_prefix/Clipper.i686-linux-gnu.tar.gz", "0ef8480ecec02c2fb8aebd50f5cdc578d33da09f7f608ddf3430b4adc4ce60d0"),
BinaryProvider.Windows(:i686) => ("$bin_prefix/Clipper.i686-w64-mingw32.tar.gz", "90df03f09ecbec00840e2f9c67a71996c37968b2ac482e6d8c58649ee4ef69a7"),
BinaryProvider.Linux(:powerpc64le, :glibc) => ("$bin_prefix/Clipper.powerpc64le-linux-gnu.tar.gz", "bc064758985bc4fda32f4c1edd5c11d64db803176d5d6bddfb74aa8fd03663e2"),
BinaryProvider.MacOS() => ("$bin_prefix/Clipper.x86_64-apple-darwin14.tar.gz", "ef7284520db5aa10a15fc0c0f45c6a61a3b1e1e050c736d9505e7b6fe5ed48bc"),
BinaryProvider.Linux(:x86_64, :glibc) => ("$bin_prefix/Clipper.x86_64-linux-gnu.tar.gz", "46d5646b9dc6bffe677fec5482d09988a8919538cb4f00da1a38e359d3ea8e6c"),
BinaryProvider.Windows(:x86_64) => ("$bin_prefix/Clipper.x86_64-w64-mingw32.tar.gz", "f74c707b2aea78424e7b4cdc28adec59770cde864d7eacde6c252a693cc7e63d"),
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"),
)
if platform_key() in keys(download_info)
# First, check to see if we're all satisfied
if any(!satisfied(p; verbose=true) for p in products)

# 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
url, tarball_hash = download_info[platform_key()]
install(url, tarball_hash; prefix=prefix, force=true, verbose=true)
install(url, tarball_hash; prefix=prefix, force=true, verbose=verbose)
end

@write_deps_file clipper_lib
else
error("Your platform $(Sys.MACHINE) is not supported by this package!")
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)
58 changes: 32 additions & 26 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,14 +33,8 @@ module Clipper

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

if isfile("../deps/deps.jl")
include("../deps/deps.jl")
check_deps()
else
error("Clipper.jl not correctly build. Please run Pkg.build(\"Clipper\") and try again!")
end

struct IntPoint
immutable IntPoint
X::Int64
Y::Int64
end
Expand Down Expand Up @@ -117,19 +125,19 @@ module Clipper
# Static functions
#==============================================================#
function orientation(path::Vector{IntPoint})
ccall((:orientation, clipper_lib), 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, clipper_lib), 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, clipper_lib), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
ccall((:pointinpolygon, cclipper), Cint, (IntPoint, Ptr{IntPoint}, Csize_t),
pt,
path,
length(path))
Expand All @@ -142,15 +150,14 @@ module Clipper
clipper_ptr::Ptr{Void}

function Clip()
clipper = new(ccall((:get_clipper, clipper_lib), Ptr{Void}, ()))
finalizer(clipper, c -> ccall((:delete_clipper, clipper_lib), 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, clipper_lib), 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 @@ -164,7 +171,7 @@ module Clipper
push!(lengths, length(path))
end

ccall((:add_paths, clipper_lib), 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 @@ -176,7 +183,7 @@ module Clipper
function execute(c::Clip, clipType::ClipType, subjFillType::PolyFillType, clipFillType::PolyFillType)
polys = Vector{Vector{IntPoint}}()

result = ccall((:execute, clipper_lib), 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 @@ -190,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, clipper_lib), Cuchar,
result = ccall((:execute_pt, cclipper), Cuchar,
(Ptr{Void}, Cint, Cint, Cint, Any, Ptr{Void}, Ptr{Void}),
c.clipper_ptr,
Int(clipType),
Expand All @@ -204,7 +211,7 @@ module Clipper
end

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

mutable struct IntRect
Expand All @@ -215,7 +222,7 @@ module Clipper
end

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

#==============================================================#
Expand All @@ -225,15 +232,15 @@ module Clipper
clipper_ptr::Ptr{Void}

function ClipperOffset(miterLimit::Float64 = 2.0, roundPrecision::Float64 = 0.25)
clipper = new(ccall((:get_clipper_offset, clipper_lib), Ptr{Void}, (Cdouble, Cdouble), miterLimit, roundPrecision))
finalizer(clipper, c -> ccall((:delete_clipper_offset, clipper_lib), 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, clipper_lib), 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 @@ -247,7 +254,7 @@ module Clipper
push!(lengths, length(path))
end

ccall((:add_offset_paths, clipper_lib), 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 @@ -257,13 +264,12 @@ module Clipper
end

function clear!(c::ClipperOffset)
ccall((:clear_offset, clipper_lib), 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, clipper_lib), 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 f9f50f8

Please sign in to comment.