|
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 |
4 | 6 |
|
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__) |
10 | 8 |
|
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) |
12 | 11 |
|
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) |
25 | 15 |
|
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") |
34 | 18 |
|
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")) |
42 | 20 |
|
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" |
46 | 23 |
|
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") |
49 | 25 |
|
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") |
53 | 28 |
|
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] |
55 | 31 |
|
56 | | - for line in hashdefs |
57 | | - m = match(r"^\s*#define\s+CURL(\w+)\s+(.+)", line) |
| 32 | + ctx = create_context(header_files, args, options) |
58 | 33 |
|
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) |
66 | 35 | end |
0 commit comments