Skip to content

Commit

Permalink
Use Clang.jl to automate C wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Aug 19, 2024
1 parent ed16344 commit c03887c
Show file tree
Hide file tree
Showing 6 changed files with 698 additions and 297 deletions.
13 changes: 7 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ uuid = "76087f3c-5699-56af-9a33-bf431cd00edd"
version = "1.0.2"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
NLopt_jll = "079eb43e-fd8e-5478-9966-2cf3e3edb778"

[weakdeps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"

[extensions]
NLoptMathOptInterfaceExt = ["MathOptInterface"]

[compat]
MathOptInterface = "1"
NLopt_jll = "2.7"
julia = "1.6"

[extensions]
NLoptMathOptInterfaceExt = ["MathOptInterface"]

[extras]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["MathOptInterface", "Test"]

[weakdeps]
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
6 changes: 6 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
NLopt_jll = "079eb43e-fd8e-5478-9966-2cf3e3edb778"

[compat]
Clang = "0.17"
33 changes: 33 additions & 0 deletions gen/gen.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright (c) 2019 Mathieu Besançon, Oscar Dowson, and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

using Clang.Generators
import NLopt_jll

c_api = joinpath(NLopt_jll.artifact_dir, "include", "nlopt.h")

build!(
create_context(
[c_api],
get_default_args(),
load_options(joinpath(@__DIR__, "generate.toml")),
),
)

header = """
# Copyright (c) 2013: Steven G. Johnson and contributors
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
#! format: off
"""

filename = joinpath(@__DIR__, "..", "src", "libnlopt.jl")
contents = read(filename, String)
contents = header * contents
contents = replace(contents, "const nlopt_opt = Ptr{nlopt_opt_s}" => "const nlopt_opt = Ptr{Cvoid}")
write(filename, contents)
7 changes: 7 additions & 0 deletions gen/generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[general]
library_name = "libnlopt"
output_file_path = "src/libnlopt.jl"
# print_enum_as_integer = true
# print_using_CEnum = false
opaque_as_mutable_struct = false
opaque_func_arg_as_PtrCvoid = true
Loading

0 comments on commit c03887c

Please sign in to comment.