Skip to content

Commit

Permalink
Improve support for Julia v1.10+, drop support for Julia v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
krrutkow committed Feb 9, 2025
1 parent 0be1c0f commit df67e98
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
fail-fast: false
matrix:
version:
- '1.5'
- '1.6'
- '1.7'
- '1.8'
Expand All @@ -25,10 +24,12 @@ jobs:
# - windows-latest
arch:
- x64
# - x86
# - aarch64
exclude:
- os: macos-latest
version: '1.5'
# - os: ubuntu-latest
# arch: aarch64
# - os: macos-latest
# arch: x64
steps:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CBinding"
uuid = "d43a6710-96b8-4a2d-833c-c424785e5374"
authors = ["Keith Rutkowski <[email protected]>"]
version = "1.0.12"
version = "1.1.0"

[deps]
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
Expand All @@ -12,4 +12,4 @@ Scratch = "6c6a2e73-6563-6170-7368-637461726353"
[compat]
Clang_jll = "^9, ^11, ^12, ^13, ^14, ^15, ^16, ^18"
Scratch = "^1"
julia = "^1.5"
julia = "^1.6"
6 changes: 3 additions & 3 deletions src/CBinding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ module CBinding

bitstype(::Type{T}; raise::Bool = true) where {T} = isbitstype(T) ? T : raise ? error("Failure to obtain a bits-type") : nothing
bitstype(::Type{CQ}; kwargs...) where {CQ<:Cqualifier} = bitstype(unqualifiedtype(CQ); kwargs...)
bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = bitstype(T; kwargs...) === nothing ? nothing : Carray{bitstype(T), N, sizeof(bitstype(T))*N}
bitstype(::Type{CA}; kwargs...) where {T, N, CA<:Carray{T, N}} = Carray{bitstype(T), N, sizeof(bitstype(T))*N}

values(::Type{CE}) where {CE<:Cenum} = bitstype(CE; raise = false) === nothing ? () : values(bitstype(CE))
values(::Type{CE}) where {CE<:Cenum} = values(bitstype(CE))

fields(::Type{CA}) where {CA<:Caggregate} = bitstype(CA; raise = false) === nothing ? () : fields(bitstype(CA))
fields(::Type{CA}) where {CA<:Caggregate} = isnothing(bitstype(CA; raise = false)) ? () : fields(bitstype(CA))


include("longdouble.jl")
Expand Down
9 changes: 5 additions & 4 deletions src/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ end



getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[]))
getexprs(ctx::Context) = getexprs(ctx, clang_getTranslationUnitCursor(ctx.tu[]); path = CXCursor[])

function getexprs(ctx::Context, syms, blocks...)
expr = filter(!isnothing, collect(blocks))
Expand Down Expand Up @@ -156,7 +156,7 @@ end



function getexprs_tu(ctx::Context, cursor::CXCursor)
function getexprs_tu(ctx::Context, cursor::CXCursor; path::Vector{CXCursor})
exprs = []

for child in children(cursor)
Expand All @@ -168,7 +168,7 @@ function getexprs_tu(ctx::Context, cursor::CXCursor)
first(range).file != header(ctx) || first(range).line > ctx.line || continue
end

append!(exprs, filter(!isnothing, getexprs(ctx, child)))
append!(exprs, filter(!isnothing, getexprs(ctx, child; path = path)))
end

return exprs
Expand Down Expand Up @@ -400,7 +400,8 @@ function wrap!(ctx::Context)
end
close(file)

libclang.Clang_jll.clang() do bin
withenv() do
bin = libclang.Clang_jll.clang()
run(`$(bin) $(ctx.args[5:7]) -w -O2 -fPIC -shared -o $(getlib(ctx).value) $(path) $(ctx.args[8:end])`) # TODO: add -rpath for all ctx.libs?
end
end
Expand Down
21 changes: 13 additions & 8 deletions src/context_c.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,15 @@ function gettype(ctx::Type{Context{:c}}, type::CXType; kwargs...)
end



function getexprs(ctx::Context{:c}, cursor::CXCursor)
function getexprs(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor})
push!(path, cursor)
exprs = []

getblock(ctx).flags.skip && return exprs
getblock(ctx).flags.defer && return exprs

if cursor.kind == CXCursor_TranslationUnit
append!(exprs, getexprs_tu(ctx, cursor))
append!(exprs, getexprs_tu(ctx, cursor; path = path))

for (_, child) in ctx.macros
append!(exprs, getexprs_macro(ctx, child))
Expand All @@ -349,11 +349,11 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
CXCursor_EnumDecl,
CXCursor_TypedefDecl,
)
append!(exprs, getexprs(ctx, child))
append!(exprs, getexprs(ctx, child; path = path))
end
end

append!(exprs, getexprs_opaque(ctx, cursor))
append!(exprs, getexprs_opaque(ctx, cursor; path = path))
elseif cursor.kind in (
CXCursor_VarDecl,
CXCursor_FunctionDecl,
Expand All @@ -366,7 +366,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
CXCursor_TypedefDecl,
CXCursor_ParmDecl,
)
append!(exprs, getexprs(ctx, child))
append!(exprs, getexprs(ctx, child; path = path))
end
end

Expand All @@ -379,7 +379,7 @@ function getexprs(ctx::Context{:c}, cursor::CXCursor)
CXCursor_EnumDecl,
CXCursor_TypedefDecl,
)
append!(exprs, getexprs(ctx, child))
append!(exprs, getexprs(ctx, child; path = path))
end
end
elseif cursor.kind == CXCursor_InclusionDirective
Expand Down Expand Up @@ -443,7 +443,7 @@ end



function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor)
function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor; path::Vector{CXCursor})
exprs = []

getblock(ctx).flags.notype && return exprs
Expand All @@ -465,6 +465,11 @@ function getexprs_opaque(ctx::Context{:c}, cursor::CXCursor)
(getjl(ctx, string(type)), nothing) :
(nothing, getjl(ctx, string(type)))

# anonymous opaque function parameters (for function pointers, not function) appear as type definitions twice it seems, so ignore this occurrence
if isanon && length(path) >= 2 && path[end-1].kind == CXCursor_ParmDecl && !any(x -> x.kind == CXCursor_FunctionDecl, path)
return exprs
end

def = clang_getCursorDefinition(cursor)
loc = getlocation(clang_getCursorLocation(def))

Expand Down
3 changes: 2 additions & 1 deletion test/layout-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function checkC(expr, val)
}
"""

return CBinding.libclang.Clang_jll.clang() do bin
return withenv() do
bin = CBinding.libclang.Clang_jll.clang()
tmp = tempname()
open(f -> write(f, code), tmp*".c", "w+")
run(`gcc -Wno-overflow -Wno-constant-conversion -Wno-address-of-packed-member -std=c99 -o $(tmp) $(tmp).c`)
Expand Down

0 comments on commit df67e98

Please sign in to comment.