Skip to content

Commit

Permalink
Add libproxtv files
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanemac committed Sep 5, 2024
1 parent 477d9a3 commit 5e89d6d
Show file tree
Hide file tree
Showing 10 changed files with 689 additions and 11 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added docs/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589"
ProxTV = "925ea013-038b-5ab6-a1ab-e0849925e528"
proxTV_jll = "700117f8-5dbb-54dd-9908-6f3eb0e21f87"

[compat]
Documenter = "1"
Binary file added src/.DS_Store
Binary file not shown.
11 changes: 0 additions & 11 deletions src/ProxTV.jl

This file was deleted.

7 changes: 7 additions & 0 deletions src/gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
proxTV_jll = "700117f8-5dbb-54dd-9908-6f3eb0e21f87"

[compat]
julia = "1.6"
9 changes: 9 additions & 0 deletions src/gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Wrapping headers

This directory contains a script that can be used to automatically generate wrappers from C headers provided by [proxTV](https://github.com/albarji/proxTV).
This is done using Clang.jl.

## Usage

Either run `julia wrapper.jl` directly, or include it and call the `main()` function.
Be sure to activate the project environment in this folder (`julia --project`), which will install `Clang.jl` and `JuliaFormatter.jl`.
8 changes: 8 additions & 0 deletions src/gen/proxtv.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[general]
use_julia_native_enum_type = true
print_using_CEnum = false
library_name = "libproxtv"

[codegen]
use_julia_bool = true
use_ccall_macro = true
41 changes: 41 additions & 0 deletions src/gen/wrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Script to parse proxTV headers and generate Julia wrappers.
using proxTV_jll
using Clang
using Clang.Generators
using JuliaFormatter

function main()
cd(@__DIR__)
include_dir = joinpath(proxTV_jll.artifact_dir, "include")
headers = [
joinpath(include_dir, header) for
header in readdir(include_dir) if endswith(header, ".h")
]

options = load_options(joinpath(@__DIR__, "proxtv.toml"))
options["general"]["output_file_path"] = joinpath("..", "libproxtv.jl")
options["general"]["output_ignorelist"] =
["mxGetInf", "sign", "min", "max", "dpttrs_", "dpttrf_"] # example: "RC_OK"

args = get_default_args()
push!(args, "-I$include_dir")
push!(args, "-DNOMATLAB")

ctx = create_context(headers, args, options)
build!(ctx)

path = options["general"]["output_file_path"]
code = read(path, String)
code = "using proxTV_jll\n\n" * code
code = replace(code, "Cdouble" => "Float64")
code = replace(code, "Cint" => "Int32")
write(path, code)

format_file(path, YASStyle())
return nothing
end

# If we want to use the file as a script with `julia wrapper.jl`
if abspath(PROGRAM_FILE) == @__FILE__
main()
end
Loading

0 comments on commit 5e89d6d

Please sign in to comment.