Skip to content

Commit 973f440

Browse files
authored
Updated package for Julia 0.7 and 1.0 (#153)
Dropped support for Julia 0.6. The package does not build on Julia 1.0 right now due to issues with upstream packages: - JuliaPackaging/BinDeps.jl#376 - JuliaPackaging/Homebrew.jl#243 Once those upstream fixes have been released, things will hopefully start to work transparently, though we may want to add version constraints in the `REQUIRE`.
1 parent 4b0d2b6 commit 973f440

File tree

12 files changed

+40
-86
lines changed

12 files changed

+40
-86
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: julia
22
julia:
3-
- 0.6
43
- 0.7
4+
- 1.0
55
- nightly
66
matrix:
77
allow_failures:
8+
- julia: 1.0
89
- julia: nightly
910
notifications:
1011
email: false

REQUIRE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
julia 0.6
1+
julia 0.7
22
BinDeps
3+
@!windows CMakeWrapper
34
@osx Homebrew

appveyor.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
environment:
22
matrix:
3-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4-
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
53
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
64
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
5+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe"
6+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
77
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
88
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
99

1010
matrix:
1111
allow_failures:
12+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/1.0/julia-1.0-latest-win32.exe"
13+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/1.0/julia-1.0-latest-win64.exe"
1214
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
1315
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"
1416

deps/build.jl

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,46 @@
1-
include("../src/compat.jl")
2-
31
# version of library to download
42
const version = v"3.2.1"
53

6-
using BinDeps
4+
using BinDeps, Libdl
75
@BinDeps.setup
86

9-
if !isdefined(Base, :Libdl)
10-
# TODO for Julia upgrade: remove check
11-
using Libdl
12-
end
13-
147
function compatible_version(lib, handle)
158
major, minor, rev = Ref{Cint}(), Ref{Cint}(), Ref{Cint}()
169
ccall(Libdl.dlsym(handle, :glfwGetVersion), Cvoid, (Ref{Cint}, Ref{Cint}, Ref{Cint}), major, minor, rev)
1710
libversion = VersionNumber(major[], minor[], rev[])
1811
return libversion >= version
1912
end
2013

21-
glfw = library_dependency("libglfw", aliases=["glfw", "glfw3", "libglfw3"], validate=compatible_version)
14+
glfw = library_dependency("glfw", aliases=["glfw", "glfw3", "libglfw", "libglfw3"], validate=compatible_version)
2215

2316
# library source code
2417
provides(Sources, URI("https://github.com/glfw/glfw/archive/$version.tar.gz"), glfw, unpacked_dir="glfw-$version")
25-
srcdir = joinpath(BinDeps.srcdir(glfw), "glfw-$version")
26-
27-
# how to build library from source
28-
cmake_options = map(x -> "-D$(x[1])=$(x[2])", [
29-
("BUILD_SHARED_LIBS", "ON"),
30-
("CMAKE_INSTALL_PREFIX", BinDeps.usrdir(glfw)),
31-
("GLFW_BUILD_DOCS", "OFF"),
32-
("GLFW_BUILD_EXAMPLES", "OFF"),
33-
("GLFW_BUILD_TESTS", "OFF")
34-
])
35-
cmake_build_steps = @build_steps begin
36-
GetSources(glfw)
37-
@build_steps begin
38-
ChangeDirectory(srcdir)
39-
`cmake $cmake_options .`
40-
MakeTargets("install")
41-
end
18+
19+
# build library from source
20+
@static if !Sys.iswindows()
21+
using CMakeWrapper
22+
build_options = [
23+
("BUILD_SHARED_LIBS", "ON"),
24+
("GLFW_BUILD_DOCS", "OFF"),
25+
("GLFW_BUILD_EXAMPLES", "OFF"),
26+
("GLFW_BUILD_TESTS", "OFF"),
27+
]
28+
build_defines = ["-D$k=$v" for (k, v) in build_options]
29+
provides(BuildProcess, CMakeProcess(cmake_args=build_defines), glfw)
4230
end
43-
provides(SimpleBuild, cmake_build_steps, glfw)
4431

45-
# get library through Homebrew, if available
46-
if isapple()
32+
# get library through Homebrew package manager
33+
@static if Sys.isapple()
4734
using Homebrew
4835
provides(Homebrew.HB, "glfw", glfw, os=:Darwin)
4936
end
5037

5138
# download a pre-compiled binary (built by GLFW)
52-
if iswindows()
39+
@static if Sys.iswindows()
5340
archive = "glfw-$version.bin.WIN$(Sys.WORD_SIZE)"
5441
libpath = joinpath(archive, "lib-mingw-w64")
5542
uri = URI("https://github.com/glfw/glfw/releases/download/$version/$archive.zip")
5643
provides(Binaries, uri, glfw, unpacked_dir=archive, installed_libpath=libpath, os=:Windows)
5744
end
5845

59-
@BinDeps.install Dict("libglfw"=>"lib")
46+
@BinDeps.install Dict(:glfw => :lib)

examples/callbacks.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using GLFW
22

3-
include("../src/compat.jl")
4-
53
window = GLFW.CreateWindow(640, 480, "GLFW Callback Test")
64
GLFW.MakeContextCurrent(window)
75

@@ -32,7 +30,7 @@ GLFW.SetDropCallback(window, (_, paths) -> println(paths))
3230

3331
glClear() = ccall(@eval(GLFW.GetProcAddress("glClear")), Cvoid, (Cuint,), 0x00004000)
3432

35-
gc() # Force garbage collection so that improper reference management is more apparent via crashes
33+
GC.gc() # Force garbage collection so that improper reference management is more apparent via crashes
3634

3735
try
3836
while !GLFW.WindowShouldClose(window)

examples/multiwindow.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ using GLFW
33
# Note: This was written as a quick test for multiwindow support.
44
# It is not a clean example (yet) of the proper way to do it.
55

6-
include("../src/compat.jl")
7-
86
windows = []
97
glClear = Dict{GLFW.Window, Function}()
108
for i in 1:3
@@ -21,7 +19,7 @@ for i in 1:3
2119
push!(windows, window)
2220
end
2321

24-
gc() # Force garbage collection so that improper reference management is more apparent via crashes
22+
GC.gc() # Force garbage collection so that improper reference management is more apparent via crashes
2523

2624
while !any(GLFW.WindowShouldClose, windows)
2725
for window in windows

src/GLFW.jl

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
__precompile__()
2-
31
module GLFW
42

5-
include("compat.jl")
63
include("../deps/deps.jl")
74

85
function GetVersion()
@@ -14,24 +11,19 @@ end
1411
include("callback.jl")
1512
include("glfw3.jl")
1613
include("vulkan.jl")
17-
18-
if isdefined(Base, :getproperty) && isdefined(Base, :setproperty!)
19-
# Julia 0.7 supports property overloading
20-
# TODO for Julia upgrade: remove feature guard
21-
include("monitor_properties.jl")
22-
end
14+
include("monitor_properties.jl")
2315

2416
const GLFW_INITIALIZED = Ref(false)
2517

2618
is_initialized() = GLFW_INITIALIZED[]
2719

28-
2920
function __init__()
3021
libversion = GetVersion()
3122

3223
if libversion.major != 3
3324
error("GLFW version $libversion not supported")
3425
end
26+
3527
# Save errors that occur during initialization
3628
errors = Vector{Exception}()
3729
SetErrorCallback(err -> push!(errors, err))
@@ -47,7 +39,7 @@ function __init__()
4739
if is_initialized()
4840
atexit(Terminate)
4941
for err in errors
50-
warn(err) # Warn about any non-fatal errors that may have occurred during initialization
42+
@warn err # Warn about any non-fatal errors that may have occurred during initialization
5143
end
5244
else
5345
throw(errors) # Throw fatal errors

src/callback.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,19 @@ function callbackcode(
3434
wrapper = Symbol('_', name, "CallbackWrapper") # _FooCallbackWrapper
3535

3636
# Separate names and types of parameters
37-
callback_param_types = Expr(:curly, :Tuple, map(paramtype, callback_params)...)
37+
callback_param_types = Expr(:tuple, map(paramtype, callback_params)...)
3838
setter_param_names = map(paramname, setter_params)
3939
setter_param_types = map(paramtype, setter_params)
4040

4141
quote
42+
# Callback wrapper that can be passed to `cfunction`
43+
$wrapper($(callback_params...)) = ($callback_ref($(callback_args...)); return nothing)
44+
4245
# Set the callback function
4346
function $setter($(setter_param_names...), callback::Function)
4447
old_callback = $callback_ref
4548
$callback_ref = callback # Prevent callback function from being garbage-collected
46-
cfunptr = cfunction($wrapper, Cvoid, $callback_param_types)
49+
cfunptr = @cfunction($wrapper, Cvoid, $callback_param_types)
4750
ccall( ($libsetter, lib), Ptr{Cvoid}, ($(setter_param_types...), Ptr{Cvoid}), $(setter_param_names...), cfunptr)
4851
return old_callback
4952
end
@@ -55,9 +58,6 @@ function callbackcode(
5558
$callback_ref = nothing # Allow former callback function to be garbage-collected
5659
return old_callback
5760
end
58-
59-
# Callback wrapper that can be passed to `cfunction`
60-
$wrapper($(callback_params...)) = ($callback_ref($(callback_args...)); return nothing)
6161
end
6262
end
6363

src/compat.jl

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/glfw3.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function Window(
303303
WindowHint(wh[1], wh[2])
304304
end
305305

306-
@static if isapple()
306+
@static if Sys.isapple()
307307
if debugging
308308
warn("OpenGL debug message callback not available on osx")
309309
debugging = false
@@ -672,5 +672,5 @@ GLFW.PollEvents() # seems to need a poll events to become active
672672
```
673673
"""
674674
function SetWindowIcon(window::Window, image::Matrix{NTuple{4, UInt8}})
675-
ccall((:glfwSetWindowIcon, lib), Void, (Window, Cint, GLFWImage), window, 1, image)
675+
ccall((:glfwSetWindowIcon, lib), Cvoid, (Window, Cint, GLFWImage), window, 1, image)
676676
end

0 commit comments

Comments
 (0)