Skip to content

Commit

Permalink
Merge d1d9a77 into bc89e3d
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Jan 15, 2018
2 parents bc89e3d + d1d9a77 commit ee42a15
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
*.jl.*.cov
*.jl.mem
*.dll
*.dylib
*.o
*.so
deps/deps.jl
deps/usr
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
GeometryTypes
@windows WinRPM
BinaryProvider
84 changes: 35 additions & 49 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,53 +1,39 @@
if is_windows()
using WinRPM
end
using BinaryProvider

function find_gpp()
if is_windows()
#TODO, is this really the hardcoded way to get the WinRPM path to g++ ?
gpp = Pkg.dir("WinRPM","deps","usr","x86_64-w64-mingw32","sys-root","mingw","bin","g++")
if !isfile(gpp*".exe")
info("g++ not found. installing gcc-c++ using WinRPM")
WinRPM.install("gcc-c++", yes = true)
WinRPM.install("gcc", yes = true)
WinRPM.install("headers", yes = true)
end
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")
push!(Base.Libdl.DL_LOAD_PATH, RPMbindir) # TODO does this need to be reversed?
ENV["PATH"] = ENV["PATH"] * ";" * RPMbindir;
return gpp, incdir
end
if is_unix()
if success(`g++ --version`)
return "g++", ""
else
error("no g++ found. Please install a version > 4.5")
end
end
end
# This is where all binaries will get installed
const prefix = Prefix(joinpath(@__DIR__, "usr"))

# generate wrapper code
include("generate_code.jl")
path = dirname(@__FILE__)
libo = joinpath(path, "build", "earcut.o")
# there are some platforms which behave weird when removing files.
# since it doesn't need to be removed, we can allow it to fail
save_rm(file) = try
rm(file)
catch e
warn(e)
end
# Instantiate products here. Examples:
earcut = LibraryProduct(prefix, "earcut")
# foo_executable = ExecutableProduct(prefix, "fooifier")
# libfoo_pc = FileProduct(joinpath(libdir(prefix), "pkgconfig", "libfoo.pc"))

# Assign products to `products`:
products = [earcut]

cd(path) do
gpp, incdir = find_gpp()
base = joinpath(path, "build")
isdir(base) || mkdir(base)
libo = joinpath(base, "earcut.o")
isfile(libo) && save_rm(libo)
run(`$gpp -c -fPIC -std=c++11 cwrapper.cpp -o $libo -I $incdir`)
lib = joinpath(base, "earcut.$(Libdl.dlext)")
isfile(lib) && save_rm(lib)
run(`$gpp -shared -o $lib $libo`)
info("Compiled EarCut successfully!")

# Download binaries from hosted location
bin_prefix = "https://github.com/SimonDanisch/EarCutDeps/releases/download/v0.1.4"
# Listing of files generated by BinaryBuilder:
# Listing of files generated by BinaryBuilder:
download_info = Dict(
BinaryProvider.Linux(:aarch64, :glibc) => ("$bin_prefix/Earcut.aarch64-linux-gnu.tar.gz", "dc137e09a22397d2b1ae8162d58e7f51469d65d73c5108460f556034ded6a9cd"),
BinaryProvider.Linux(:armv7l, :glibc) => ("$bin_prefix/Earcut.arm-linux-gnueabihf.tar.gz", "ffc7c5589c0bb0389d4957e320f5094df98fc254091b97ba894e9bb19cac223f"),
BinaryProvider.Linux(:i686, :glibc) => ("$bin_prefix/Earcut.i686-linux-gnu.tar.gz", "5b838d58a6ca1bc6a50b2618c3f903e2964e326511041a2be4b03ea831679927"),
BinaryProvider.Windows(:i686) => ("$bin_prefix/Earcut.i686-w64-mingw32.tar.gz", "83d4833cd645e3fdc0040cfb47d6082f57b9e0a67aae48fb41fc6614e16de10b"),
BinaryProvider.Linux(:powerpc64le, :glibc) => ("$bin_prefix/Earcut.powerpc64le-linux-gnu.tar.gz", "1d18b6397dfaeb89297d639ae8178bf830414182689e86fb513edd652e6f6872"),
BinaryProvider.MacOS() => ("$bin_prefix/Earcut.x86_64-apple-darwin14.tar.gz", "bbbf711726bf25bf2fd496938fb55ada2c688bcc3aa34127c42081225f539eeb"),
BinaryProvider.Linux(:x86_64, :glibc) => ("$bin_prefix/Earcut.x86_64-linux-gnu.tar.gz", "53b6e41d7319b5a957ab59ddca224e4667577d4c0560fd0868e2aa1ff2b521a7"),
BinaryProvider.Windows(:x86_64) => ("$bin_prefix/Earcut.x86_64-w64-mingw32.tar.gz", "42e63d547f5320a778375b6ebab4bd74a61d80972b71ed20a0c379c83fb0500b"),
)
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)
# Download and install binaries
url, tarball_hash = download_info[platform_key()]
install(url, tarball_hash; prefix=prefix, force=true, verbose=true)
end
@write_deps_file earcut
else
error("Your platform $(Sys.MACHINE) is not supported by this package!")
end
17 changes: 5 additions & 12 deletions src/cwrapper.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
const lib = Libdl.find_library(
["earcut"],
[joinpath(dirname(@__FILE__), "..", "deps", "build")]
)
if isempty(lib)
error("Library not found. Please run Pkg.build(\"EarCut\").")
end
include("../deps/deps.jl")

function triangulate(polygon::Vector{Vector{Point{2, Float64}}})
lengths = map(x-> UInt32(length(x)), polygon)
len = UInt32(length(lengths))
array = ccall(
(:u32_triangulate_f64, lib),
(:u32_triangulate_f64, earcut),
Tuple{Ptr{GLTriangle}, Cint},
(Ptr{Ptr{Float64}}, Ptr{UInt32}, UInt32),
polygon, lengths, len
Expand All @@ -22,7 +16,7 @@ function triangulate(polygon::Vector{Vector{Point{2, Float32}}})
lengths = map(x-> UInt32(length(x)), polygon)
len = UInt32(length(lengths))
array = ccall(
(:u32_triangulate_f32, lib),
(:u32_triangulate_f32, earcut),
Tuple{Ptr{GLTriangle}, Cint},
(Ptr{Ptr{Float32}}, Ptr{UInt32}, UInt32),
polygon, lengths, len
Expand All @@ -34,7 +28,7 @@ function triangulate(polygon::Vector{Vector{Point{2, Int64}}})
lengths = map(x-> UInt32(length(x)), polygon)
len = UInt32(length(lengths))
array = ccall(
(:u32_triangulate_i64, lib),
(:u32_triangulate_i64, earcut),
Tuple{Ptr{GLTriangle}, Cint},
(Ptr{Ptr{Int64}}, Ptr{UInt32}, UInt32),
polygon, lengths, len
Expand All @@ -46,11 +40,10 @@ function triangulate(polygon::Vector{Vector{Point{2, Int32}}})
lengths = map(x-> UInt32(length(x)), polygon)
len = UInt32(length(lengths))
array = ccall(
(:u32_triangulate_i32, lib),
(:u32_triangulate_i32, earcut),
Tuple{Ptr{GLTriangle}, Cint},
(Ptr{Ptr{Int32}}, Ptr{UInt32}, UInt32),
polygon, lengths, len
)
unsafe_wrap(Vector{GLTriangle}, array[1], array[2])
end

0 comments on commit ee42a15

Please sign in to comment.