Skip to content

Commit 38dae7b

Browse files
committed
Upgrade the wrapper script and rework the pacakge for multi-platform support
1 parent ee2410e commit 38dae7b

23 files changed

Lines changed: 29442 additions & 3022 deletions

gen/Manifest.toml

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
3+
LibCURL_jll = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
4+
MozillaCACerts_jll = "14a3606d-f60d-562e-9121-12d972cd8159"
5+
6+
[compat]
7+
Clang = "0.14"
8+
LibCURL_jll = "7.66"
9+
MozillaCACerts_jll = ">= 2020"

gen/generate.jl

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,35 @@
1-
using Clang.cindex
2-
using Clang.wrap_c
3-
using Printf
1+
using Pkg
2+
using Pkg.Artifacts
3+
using Clang.Generators
4+
using Clang.Generators.JLLEnvs
5+
using LibCURL_jll
46

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

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

13-
headers = map(x -> joinpath(CURL_PATH, x), ["curl.h", "easy.h", "multi.h"])
14-
context = wrap_c.init(;
15-
headers = headers,
16-
clang_args = String[],
17-
common_file = joinpath(SRC_DIR, "lC_common_h.jl"),
18-
clang_includes = CLANG_INCLUDES,
19-
clang_diagnostics = true,
20-
header_wrapped = (top_header, cursor_header) -> in(cursor_header, headers),
21-
header_library = header -> "libcurl",
22-
header_outputfile = header -> joinpath(SRC_DIR, "lC_") * replace(basename(header), "." => "_") * ".jl",
23-
)
24-
context.options.wrap_structs = true
12+
include_dir = joinpath(artifact_dir, "include") |> normpath
13+
curl_h = joinpath(include_dir, "curl", "curl.h")
14+
@assert isfile(curl_h)
2515

26-
begin
27-
context.headers = [joinpath(CURL_PATH, "curl.h")]
28-
run(context)
29-
end
30-
31-
function write_constants(filename::AbstractString, startswith_identifier::AbstractString, exports_file)
32-
open(filename, "r") do file
33-
lines = split(read(file, String), "\n")
16+
# mprintf_h = joinpath(include_dir, "curl", "mprintf.h")
17+
# stdcheaders_h = joinpath(include_dir, "curl", "stdcheaders.h")
3418

35-
for line in lines
36-
if startswith(line, startswith_identifier)
37-
@printf exports_file "export %s\n" split(line, r" |\(")[2]
38-
end
39-
end
40-
end
41-
end
19+
options = load_options(joinpath(@__DIR__, "generator.toml"))
4220

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

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

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

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

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

59-
if m !== nothing
60-
c2 = replace(m.captures[2], "(unsigned long)" => "")
61-
@printf defines_file "const CURL%-30s = %s\n" m.captures[1] c2
62-
@printf exports_file "export CURL%s\n" m.captures[1]
63-
end
64-
end
65-
end
34+
build!(ctx)
6635
end

gen/generator.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[general]
2+
library_name = "libcurl"
3+
use_julia_native_enum_type = true
4+
use_deterministic_symbol = true
5+
auto_mutability = true
6+
7+
printer_blacklist = [
8+
"CURL_SUFFIX_CURL_OFF_T",
9+
"CURL_SUFFIX_CURL_OFF_TU",
10+
"CURL_ZERO_TERMINATED",
11+
]
12+
13+
[codegen.macro]
14+
macro_mode = "basic"

0 commit comments

Comments
 (0)