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

+29442
-3022
lines changed

gen/Manifest.toml

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[ArgTools]]
4+
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
5+
6+
[[Artifacts]]
7+
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
8+
9+
[[Base64]]
10+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
11+
12+
[[CEnum]]
13+
git-tree-sha1 = "215a9aa4a1f23fbd05b92769fdd62559488d70e9"
14+
uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
15+
version = "0.4.1"
16+
17+
[[Clang]]
18+
deps = ["CEnum", "Clang_jll", "Downloads", "Pkg", "TOML"]
19+
git-tree-sha1 = "93b424759f11b7dbd300eb424fa1bfe590e15cf6"
20+
repo-rev = "master"
21+
repo-url = "https://github.com/JuliaInterop/Clang.jl.git"
22+
uuid = "40e3b903-d033-50b4-a0cc-940c62c95e31"
23+
version = "0.14.0"
24+
25+
[[Clang_jll]]
26+
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "libLLVM_jll"]
27+
git-tree-sha1 = "a5923c06de3178dd755f4b9411ea8922a7ae6fb8"
28+
uuid = "0ee61d77-7f21-5576-8119-9fcc46b10100"
29+
version = "11.0.1+3"
30+
31+
[[Dates]]
32+
deps = ["Printf"]
33+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
34+
35+
[[Downloads]]
36+
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
37+
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
38+
39+
[[InteractiveUtils]]
40+
deps = ["Markdown"]
41+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
42+
43+
[[JLLWrappers]]
44+
deps = ["Preferences"]
45+
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e"
46+
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
47+
version = "1.3.0"
48+
49+
[[LibCURL]]
50+
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
51+
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
52+
53+
[[LibCURL_jll]]
54+
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
55+
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
56+
57+
[[LibGit2]]
58+
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
59+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
60+
61+
[[LibSSH2_jll]]
62+
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
63+
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
64+
65+
[[Libdl]]
66+
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
67+
68+
[[Logging]]
69+
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
70+
71+
[[Markdown]]
72+
deps = ["Base64"]
73+
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
74+
75+
[[MbedTLS_jll]]
76+
deps = ["Artifacts", "Libdl"]
77+
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
78+
79+
[[MozillaCACerts_jll]]
80+
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
81+
82+
[[NetworkOptions]]
83+
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
84+
85+
[[Pkg]]
86+
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
87+
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
88+
89+
[[Preferences]]
90+
deps = ["TOML"]
91+
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a"
92+
uuid = "21216c6a-2e73-6563-6e65-726566657250"
93+
version = "1.2.2"
94+
95+
[[Printf]]
96+
deps = ["Unicode"]
97+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
98+
99+
[[REPL]]
100+
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
101+
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
102+
103+
[[Random]]
104+
deps = ["Serialization"]
105+
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
106+
107+
[[SHA]]
108+
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
109+
110+
[[Serialization]]
111+
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
112+
113+
[[Sockets]]
114+
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
115+
116+
[[TOML]]
117+
deps = ["Dates"]
118+
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
119+
120+
[[Tar]]
121+
deps = ["ArgTools", "SHA"]
122+
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
123+
124+
[[UUIDs]]
125+
deps = ["Random", "SHA"]
126+
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
127+
128+
[[Unicode]]
129+
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
130+
131+
[[Zlib_jll]]
132+
deps = ["Libdl"]
133+
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
134+
135+
[[libLLVM_jll]]
136+
deps = ["Artifacts", "Libdl"]
137+
uuid = "8f36deef-c2a5-5394-99ed-8e07531fb29a"
138+
139+
[[nghttp2_jll]]
140+
deps = ["Artifacts", "Libdl"]
141+
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
142+
143+
[[p7zip_jll]]
144+
deps = ["Artifacts", "Libdl"]
145+
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"

gen/Project.toml

+9
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

+23-54
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

+14
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)