Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
Pkg.add(PackageSpec(name="JuliaFormatter", version="2"))
using JuliaFormatter
format(".", verbose=true)
out = String(read(Cmd(`git diff`)))
Expand Down
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name = "DSDP"
uuid = "2714ae6b-e930-5b4e-9c21-d0bacf577842"
repo = "https://github.com/jump-dev/DSDP.jl.git"
version = "0.2.1"
repo = "https://github.com/jump-dev/DSDP.jl.git"

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

[compat]
CEnum = "0.5.0"
DSDP_jll = "0.0.1"
MathOptInterface = "1"
julia = "1.10"
Expand Down
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"
DSDP_jll = "1065e140-e56c-5613-be8b-7480bf7138df"

[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.

import Clang
import DSDP_jll

dir = joinpath(DSDP_jll.artifact_dir, "include")
Clang.Generators.create_context(
joinpath.(dir, ["dsdp5.h"]),
[Clang.Generators.get_default_args(); "-I$dir"],
Clang.Generators.load_options(joinpath(@__DIR__, "generate.toml")),
) |> Clang.Generators.build!

filename = joinpath(@__DIR__, "..", "src", "libdsdp.jl")
contents = read(filename, String)
for cone in ["DSDP", "SDPCone", "LPCone", "BCone"]
global contents = replace(
contents,
"const $(cone)_C = Cvoid\n\n" => "",
"const $(cone) = Ptr{$(cone)_C}\n\n" => "",
"::$(cone)," => "::Ptr{Cvoid},",
"::$(cone))" => "::Ptr{Cvoid})",
"{$(cone)}" => "{Ptr{Cvoid}}",
)
end
contents = replace(contents, r"const .+?\n\n" => "")
contents = replace(contents, r"# Skipping.+" => "")
for _ in 1:10
global contents = replace(contents, "\n\n\n" => "\n\n")
end
write(filename, contents)
13 changes: 13 additions & 0 deletions gen/generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[general]
library_name = "libdsdp"
output_file_path = "src/libdsdp.jl"
print_using_CEnum = false
prologue_file_path = "gen/prologue.jl"
use_deterministic_symbol = true

[codegen]
opaque_as_mutable_struct = false
use_ccall_macro = true

[codegen.macro]
macro_mode = "basic"
7 changes: 7 additions & 0 deletions gen/prologue.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2022: Joey Huchette, Benoît Legat, 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.

# Disable JuliaFormatter for this file.
#!format:off
83 changes: 7 additions & 76 deletions src/DSDP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,84 +5,15 @@

module DSDP

import DSDP_jll
using CEnum: @cenum
using DSDP_jll: libdsdp
import LinearAlgebra
import MathOptInterface as MOI

using LinearAlgebra
include("libdsdp.jl")

macro dsdp_ccall(f, args...)
quote
# QuoteNode prevents the interpretion of the symbol
# and leave it as a symbol
info =
ccall(($(QuoteNode(f)), DSDP_jll.libdsdp), Cint, $(esc.(args)...))
if !iszero(info)
error("DSDP call $($(QuoteNode(f))) returned nonzero status $info.")
end
end
end

const DSDPT = Ptr{Nothing}

include("dsdp5_enums.jl")
include("dsdp5_API.jl")

include("lpcone.jl")
function CreateLPCone(dsdp::DSDPT)
lpcone = Ref{LPCone.LPConeT}()
@dsdp_ccall DSDPCreateLPCone (DSDPT, Ref{LPCone.LPConeT}) dsdp lpcone
return lpcone[]
end

include("sdpcone.jl")
function CreateSDPCone(dsdp::DSDPT, n::Integer)
sdpcone = Ref{SDPCone.SDPConeT}()
@dsdp_ccall DSDPCreateSDPCone (DSDPT, Cint, Ref{SDPCone.SDPConeT}) dsdp n sdpcone
return sdpcone[]
end

include("bcone.jl")
function CreateBCone(dsdp::DSDPT)
bcone = Ref{BCone.BConeT}()
@dsdp_ccall DSDPCreateBCone (DSDPT, Ref{BCone.BConeT}) dsdp bcone
return bcone[]
end

# Writes to `input.sdpa`
function PrintData(
dsdp::DSDPT,
sdpcone::SDPCone.SDPConeT,
lpcone::LPCone.LPConeT,
)
@dsdp_ccall DSDPPrintData (DSDPT, SDPCone.SDPConeT, LPCone.LPConeT) dsdp sdpcone lpcone
end

function PrintSolution(
fp::Libc.FILE,
dsdp::DSDPT,
sdpcone::SDPCone.SDPConeT,
lpcone::LPCone.LPConeT,
)
@dsdp_ccall DSDPPrintSolution (
Ptr{Cvoid},
DSDPT,
SDPCone.SDPConeT,
LPCone.LPConeT,
) fp dsdp sdpcone lpcone
end

function PrintSolution(
dsdp::DSDPT,
sdpcone::SDPCone.SDPConeT,
lpcone::LPCone.LPConeT,
)
# See https://discourse.julialang.org/t/access-c-stdout-in-julia/24187/2
stdout = Libc.FILE(Libc.RawFD(1), "w")
return PrintSolution(stdout, dsdp, sdpcone, lpcone)
end

#function PrintSolution(arg1, arg2::DSDPT, arg3::SDPCone.SDPConeT, arg4::LPCone.LPConeT)
# @dsdp_ccall DSDPPrintSolution (Ptr{FILE}, DSDP, SDPCone.SDPConeT, LPCone.LPConeT) arg1 arg2 arg3 arg4
#end
# This one is named poorly in the upstream C API
const DSDPSetReuseMatrix = DSDPReuseMatrix

include("MOI_wrapper.jl")

Expand Down
Loading
Loading