Skip to content

Commit cf05695

Browse files
committed
Refactor into src/libdsdp.jl
1 parent 4575ce3 commit cf05695

22 files changed

+1213
-1598
lines changed

.github/workflows/format_check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
shell: julia --color=yes {0}
1919
run: |
2020
using Pkg
21-
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
21+
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
2222
using JuliaFormatter
2323
format(".", verbose=true)
2424
out = String(read(Cmd(`git diff`)))

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
name = "DSDP"
22
uuid = "2714ae6b-e930-5b4e-9c21-d0bacf577842"
3-
repo = "https://github.com/jump-dev/DSDP.jl.git"
43
version = "0.2.1"
4+
repo = "https://github.com/jump-dev/DSDP.jl.git"
55

66
[deps]
7+
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
78
DSDP_jll = "1065e140-e56c-5613-be8b-7480bf7138df"
89
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
910
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
1011

1112
[compat]
13+
CEnum = "0.5.0"
1214
DSDP_jll = "0.0.1"
1315
MathOptInterface = "1"
1416
julia = "1.10"

gen/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[deps]
2+
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
3+
DSDP_jll = "1065e140-e56c-5613-be8b-7480bf7138df"
4+
5+
[compat]
6+
Clang = "0.17"

gen/gen.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2019 Mathieu Besançon, Oscar Dowson, and contributors
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be found
4+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
5+
6+
import Clang
7+
import DSDP_jll
8+
9+
dir = joinpath(DSDP_jll.artifact_dir, "include")
10+
Clang.Generators.create_context(
11+
joinpath.(dir, ["dsdp5.h"]),
12+
[Clang.Generators.get_default_args(); "-I$dir"],
13+
Clang.Generators.load_options(joinpath(@__DIR__, "generate.toml")),
14+
) |> Clang.Generators.build!
15+
16+
filename = joinpath(@__DIR__, "..", "src", "libdsdp.jl")
17+
contents = read(filename, String)
18+
for cone in ["DSDP", "SDPCone", "LPCone", "BCone"]
19+
global contents = replace(
20+
contents,
21+
"const $(cone)_C = Cvoid\n\n" => "",
22+
"const $(cone) = Ptr{$(cone)_C}\n\n" => "",
23+
"::$(cone)," => "::Ptr{Cvoid},",
24+
"::$(cone))" => "::Ptr{Cvoid})",
25+
"{$(cone)}" => "{Ptr{Cvoid}}",
26+
)
27+
end
28+
contents = replace(contents, r"const .+?\n\n" => "")
29+
contents = replace(contents, r"# Skipping.+" => "")
30+
for _ in 1:10
31+
global contents = replace(contents, "\n\n\n" => "\n\n")
32+
end
33+
write(filename, contents)

gen/generate.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[general]
2+
library_name = "libdsdp"
3+
output_file_path = "src/libdsdp.jl"
4+
print_using_CEnum = false
5+
prologue_file_path = "gen/prologue.jl"
6+
use_deterministic_symbol = true
7+
8+
[codegen]
9+
opaque_as_mutable_struct = false
10+
use_ccall_macro = true
11+
12+
[codegen.macro]
13+
macro_mode = "basic"

gen/prologue.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) 2022: Joey Huchette, Benoît Legat, and contributors
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be found
4+
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
5+
6+
# Disable JuliaFormatter for this file.
7+
#!format:off

src/DSDP.jl

Lines changed: 7 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,84 +5,15 @@
55

66
module DSDP
77

8-
import DSDP_jll
8+
using CEnum: @cenum
9+
using DSDP_jll: libdsdp
10+
import LinearAlgebra
11+
import MathOptInterface as MOI
912

10-
using LinearAlgebra
13+
include("libdsdp.jl")
1114

12-
macro dsdp_ccall(f, args...)
13-
quote
14-
# QuoteNode prevents the interpretion of the symbol
15-
# and leave it as a symbol
16-
info =
17-
ccall(($(QuoteNode(f)), DSDP_jll.libdsdp), Cint, $(esc.(args)...))
18-
if !iszero(info)
19-
error("DSDP call $($(QuoteNode(f))) returned nonzero status $info.")
20-
end
21-
end
22-
end
23-
24-
const DSDPT = Ptr{Nothing}
25-
26-
include("dsdp5_enums.jl")
27-
include("dsdp5_API.jl")
28-
29-
include("lpcone.jl")
30-
function CreateLPCone(dsdp::DSDPT)
31-
lpcone = Ref{LPCone.LPConeT}()
32-
@dsdp_ccall DSDPCreateLPCone (DSDPT, Ref{LPCone.LPConeT}) dsdp lpcone
33-
return lpcone[]
34-
end
35-
36-
include("sdpcone.jl")
37-
function CreateSDPCone(dsdp::DSDPT, n::Integer)
38-
sdpcone = Ref{SDPCone.SDPConeT}()
39-
@dsdp_ccall DSDPCreateSDPCone (DSDPT, Cint, Ref{SDPCone.SDPConeT}) dsdp n sdpcone
40-
return sdpcone[]
41-
end
42-
43-
include("bcone.jl")
44-
function CreateBCone(dsdp::DSDPT)
45-
bcone = Ref{BCone.BConeT}()
46-
@dsdp_ccall DSDPCreateBCone (DSDPT, Ref{BCone.BConeT}) dsdp bcone
47-
return bcone[]
48-
end
49-
50-
# Writes to `input.sdpa`
51-
function PrintData(
52-
dsdp::DSDPT,
53-
sdpcone::SDPCone.SDPConeT,
54-
lpcone::LPCone.LPConeT,
55-
)
56-
@dsdp_ccall DSDPPrintData (DSDPT, SDPCone.SDPConeT, LPCone.LPConeT) dsdp sdpcone lpcone
57-
end
58-
59-
function PrintSolution(
60-
fp::Libc.FILE,
61-
dsdp::DSDPT,
62-
sdpcone::SDPCone.SDPConeT,
63-
lpcone::LPCone.LPConeT,
64-
)
65-
@dsdp_ccall DSDPPrintSolution (
66-
Ptr{Cvoid},
67-
DSDPT,
68-
SDPCone.SDPConeT,
69-
LPCone.LPConeT,
70-
) fp dsdp sdpcone lpcone
71-
end
72-
73-
function PrintSolution(
74-
dsdp::DSDPT,
75-
sdpcone::SDPCone.SDPConeT,
76-
lpcone::LPCone.LPConeT,
77-
)
78-
# See https://discourse.julialang.org/t/access-c-stdout-in-julia/24187/2
79-
stdout = Libc.FILE(Libc.RawFD(1), "w")
80-
return PrintSolution(stdout, dsdp, sdpcone, lpcone)
81-
end
82-
83-
#function PrintSolution(arg1, arg2::DSDPT, arg3::SDPCone.SDPConeT, arg4::LPCone.LPConeT)
84-
# @dsdp_ccall DSDPPrintSolution (Ptr{FILE}, DSDP, SDPCone.SDPConeT, LPCone.LPConeT) arg1 arg2 arg3 arg4
85-
#end
15+
# This one is named poorly in the upstream C API
16+
const DSDPSetReuseMatrix = DSDPReuseMatrix
8617

8718
include("MOI_wrapper.jl")
8819

0 commit comments

Comments
 (0)