Skip to content

Commit 44d6dee

Browse files
committed
Switched away from CBindings to use statically generated wrapper via clang.jl
1 parent a12f08f commit 44d6dee

9 files changed

Lines changed: 907 additions & 738 deletions

File tree

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name = "Minc2"
22
uuid = "8e6f2f06-34e2-40fe-8437-e396464d2a7f"
3-
version = "0.1.9"
3+
version = "0.2.0"
44
authors = ["Vladimir S. FONOV <vladimir.fonov@gmail.com>"]
55

66
[deps]
7-
CBinding = "d43a6710-96b8-4a2d-833c-c424785e5374"
7+
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
88
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1010
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -16,7 +16,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
1616
libminc_jll = "dce2f2bf-0ed4-5a0e-8af7-a90b827a9344"
1717

1818
[compat]
19-
CBinding = "1"
19+
CEnum = "0.5.0"
2020
Interpolations = "0.14, 0.15, 0.16"
2121
NIfTI = "0.6"
2222
Requires = "1"

gen/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
3+
libminc_jll = "dce2f2bf-0ed4-5a0e-8af7-a90b827a9344"

gen/generator.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Clang.Generators
2+
using libminc_jll
3+
using Pkg
4+
5+
cd(@__DIR__)
6+
7+
# Get include directory from jll
8+
include_dir = joinpath(libminc_jll.artifact_dir, "include")
9+
10+
# Generator options
11+
options = load_options(joinpath(@__DIR__, "generator.toml"))
12+
13+
# Compiler args (include paths)
14+
args = get_default_args()
15+
push!(args, "-I$include_dir")
16+
17+
# The header file to parse
18+
headers = [joinpath(include_dir, "minc2-simple.h")]
19+
20+
# Create and run generator
21+
@info "Generating bindings for minc2-simple..."
22+
ctx = create_context(headers, args, options)
23+
24+
# Write output to ../src/LibMinc2Simple.jl
25+
build!(ctx)
26+

gen/generator.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[library]
2+
name = "LibMinc2Simple"
3+
output_base = "../src/LibMinc2Simple"
4+
prologue_file_path = ""
5+
6+
[codegen]
7+
use_julia_native_enum = true
8+
use_ccall_macro = false
9+
markdown_output = "index.md"
10+
11+
# How to handle opaque pointers (void*)
12+
# "cvoid" maps to `Ptr{Cvoid}`, which is standard.opaque_func_arg_as_ptr = true
13+
opaque_func_arg_as_ptr = true
14+
15+
# If true, C enums are mapped to Julia @enum.
16+
# If false, they are mapped to Cint constants (which is often easier for bitwise flags).
17+
use_deterministic_symbol = true
18+
19+
20+
[general]
21+
# The name of the module to generate
22+
module_name = "LibMinc"
23+
24+
# The name of the JLL package that provides the shared library
25+
jll_pkg_name = "libminc_jll"
26+
27+
# The specific library constant to export from the JLL.
28+
library_name = "libminc2_simple"
29+
30+
# Output file for the generated code
31+
output_file_path = "../src/LibMinc.jl"
32+
33+
# Common prefixes to export automatically
34+
# This prevents polluting the namespace with internal C symbols
35+
export_symbol_prefixes = ["minc2_", "MINC2_", "miget_", "miset_"]
36+
37+
# Optional: Generate strictly typed functions (default is false, which uses Any for some pointers)
38+
# true is generally better for performance/safety but requires cleaner headers.
39+
is_function_strictly_typed = true
40+
41+
42+
# Optional: Map C booleans to Julia Bool
43+
use_julia_bool = true
44+

0 commit comments

Comments
 (0)