Skip to content

Commit e2e0b6f

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

34 files changed

+27258
-3022
lines changed

gen/Project.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
LibCURL_jll = "7.66"
8+
MozillaCACerts_jll = ">= 2020"

gen/configs/aarch64-linux-gnu.toml

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

gen/configs/aarch64-linux-musl.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/aarch64-linux-musl.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/armv7l-linux-gnueabihf.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/armv7l-linux-musleabihf.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"

gen/configs/i686-linux-gnu.toml

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

gen/configs/i686-linux-musl.toml

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

gen/configs/i686-w64-mingw32.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/i686-w64-mingw32.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/powerpc64le-linux-gnu.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[general]
2+
library_name = "libcurl"
3+
output_file_path = "../src/wrappers/x86_64-apple-darwin14.jl"
4+
5+
use_julia_native_enum_type = true
6+
use_deterministic_symbol = true
7+
auto_mutability = true
8+
9+
printer_blacklist = [
10+
"CURL_SUFFIX_CURL_OFF_T",
11+
"CURL_SUFFIX_CURL_OFF_TU",
12+
"CURL_ZERO_TERMINATED",
13+
]
14+
15+
[codegen.macro]
16+
macro_mode = "basic"

gen/configs/x86_64-linux-gnu.toml

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

gen/configs/x86_64-linux-musl.toml

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

gen/configs/x86_64-w64-mingw32.toml

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

gen/generate.jl

Lines changed: 28 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,40 @@
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+
target = "aarch64-linux-gnu"
20+
for target in JLLEnvs.JLL_ENV_TRIPLES
21+
target == "aarch64-apple-darwin20" && continue
4222

43-
# Generate export statements
44-
open(joinpath(SRC_DIR, "lC_exports_h.jl"), "w+") do exports_file
45-
println(exports_file, "# Generating exports")
23+
@info "processing $target"
4624

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)
25+
options = load_options(joinpath(@__DIR__, "configs", "$target.toml"))
4926

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

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

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

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
35+
build!(ctx)
6636
end
37+
38+
39+
40+

gen/generator.toml

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

0 commit comments

Comments
 (0)