Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .ci/change-uuid.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using UUIDs

project_filename = joinpath(dirname(@__DIR__), "Project.toml")

write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"$(uuid4())\"\n"))
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ jobs:
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- run: julia --color=yes test/libcurl_uuid.jl
- run: julia --color=yes .ci/change-uuid.jl
- uses: julia-actions/julia-buildpkg@v1
- name: Run tests
run: |
julia --project --color=yes -e 'using UUIDs; write("Project.toml", replace(read("Project.toml", String), r"uuid = .*?\n" =>"uuid = \"$(uuid4())\"\n"));'
julia --project --color=yes --check-bounds=yes -e 'import Pkg; Pkg.build(); Pkg.test(; coverage=true)'
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down
145 changes: 145 additions & 0 deletions gen/Manifest.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
Comment thread
Gnimuc marked this conversation as resolved.
LibCURL_jll = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
MozillaCACerts_jll = "14a3606d-f60d-562e-9121-12d972cd8159"

[compat]
Clang = "0.14"
LibCURL_jll = "7.66"
MozillaCACerts_jll = ">= 2020"
77 changes: 23 additions & 54 deletions gen/generate.jl
Original file line number Diff line number Diff line change
@@ -1,66 +1,35 @@
using Clang.cindex
using Clang.wrap_c
using Printf
using Pkg
using Pkg.Artifacts
using Clang.Generators
using Clang.Generators.JLLEnvs
using LibCURL_jll

# Set these to correspond to your local filesystem's curl and clang include paths
const CURL_PATH = "/usr/local/opt/curl/include/curl"
const CLANG_INCLUDES = [
"/usr/local/opt/llvm/include",
]
cd(@__DIR__)

const SRC_DIR = abspath(@__DIR__, "..", "src")
artifact_toml = joinpath(dirname(pathof(LibCURL_jll)), "..", "StdlibArtifacts.toml")
artifact_dir = Pkg.Artifacts.ensure_artifact_installed("LibCURL", artifact_toml)

headers = map(x -> joinpath(CURL_PATH, x), ["curl.h", "easy.h", "multi.h"])
context = wrap_c.init(;
headers = headers,
clang_args = String[],
common_file = joinpath(SRC_DIR, "lC_common_h.jl"),
clang_includes = CLANG_INCLUDES,
clang_diagnostics = true,
header_wrapped = (top_header, cursor_header) -> in(cursor_header, headers),
header_library = header -> "libcurl",
header_outputfile = header -> joinpath(SRC_DIR, "lC_") * replace(basename(header), "." => "_") * ".jl",
)
context.options.wrap_structs = true
include_dir = joinpath(artifact_dir, "include") |> normpath
curl_h = joinpath(include_dir, "curl", "curl.h")
@assert isfile(curl_h)

begin
context.headers = [joinpath(CURL_PATH, "curl.h")]
run(context)
end

function write_constants(filename::AbstractString, startswith_identifier::AbstractString, exports_file)
open(filename, "r") do file
lines = split(read(file, String), "\n")
# mprintf_h = joinpath(include_dir, "curl", "mprintf.h")
# stdcheaders_h = joinpath(include_dir, "curl", "stdcheaders.h")

for line in lines
if startswith(line, startswith_identifier)
@printf exports_file "export %s\n" split(line, r" |\(")[2]
end
end
end
end
options = load_options(joinpath(@__DIR__, "generator.toml"))

# Generate export statements
open(joinpath(SRC_DIR, "lC_exports_h.jl"), "w+") do exports_file
println(exports_file, "# Generating exports")
for target in JLLEnvs.JLL_ENV_TRIPLES
@info "processing $target"

write_constants(joinpath(SRC_DIR, "lC_curl_h.jl"), "function", exports_file)
write_constants(joinpath(SRC_DIR, "lC_common_h.jl"), "const", exports_file)
options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "lib", "$target.jl")

# Generate define constants
open(joinpath(SRC_DIR, "lC_defines_h.jl"), "w+") do defines_file
println(defines_file, "# Generating #define constants")
args = get_default_args(target)
push!(args, "-I$include_dir")

hashdefs = split(read(`gcc -E -dD -P $(joinpath(CURL_PATH, "curl.h"))`, String), "\n")
# header_files = detect_headers(include_dir, args)
header_files = [curl_h]

for line in hashdefs
m = match(r"^\s*#define\s+CURL(\w+)\s+(.+)", line)
ctx = create_context(header_files, args, options)

if m !== nothing
c2 = replace(m.captures[2], "(unsigned long)" => "")
@printf defines_file "const CURL%-30s = %s\n" m.captures[1] c2
@printf exports_file "export CURL%s\n" m.captures[1]
end
end
end
build!(ctx)
end
14 changes: 14 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[general]
library_name = "libcurl"
use_julia_native_enum_type = true
use_deterministic_symbol = true
auto_mutability = true

printer_blacklist = [
"CURL_SUFFIX_CURL_OFF_T",
"CURL_SUFFIX_CURL_OFF_TU",
"CURL_ZERO_TERMINATED",
]

[codegen.macro]
macro_mode = "basic"
Loading