Skip to content

Commit

Permalink
Upgrade the wrapper script and rework the pacakge for multi-platform …
Browse files Browse the repository at this point in the history
…support
  • Loading branch information
Gnimuc committed Apr 29, 2021
1 parent ee2410e commit e2e0b6f
Show file tree
Hide file tree
Showing 34 changed files with 27,258 additions and 3,022 deletions.
8 changes: 8 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
LibCURL_jll = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
MozillaCACerts_jll = "14a3606d-f60d-562e-9121-12d972cd8159"

[compat]
LibCURL_jll = "7.66"
MozillaCACerts_jll = ">= 2020"
16 changes: 16 additions & 0 deletions gen/configs/aarch64-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/aarch64-linux-gnu.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/aarch64-linux-musl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/aarch64-linux-musl.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/armv7l-linux-gnueabihf.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/armv7l-linux-gnueabihf.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/armv7l-linux-musleabihf.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/armv7l-linux-musleabihf.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/i686-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/i686-linux-gnu.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/i686-linux-musl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/i686-linux-musl.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/i686-w64-mingw32.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/i686-w64-mingw32.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/powerpc64le-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/powerpc64le-linux-gnu.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/x86_64-apple-darwin14.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/x86_64-apple-darwin14.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/x86_64-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/x86_64-linux-gnu.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/x86_64-linux-musl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/x86_64-linux-musl.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/x86_64-unknown-freebsd11.1.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/x86_64-unknown-freebsd11.1.jl"

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"
16 changes: 16 additions & 0 deletions gen/configs/x86_64-w64-mingw32.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[general]
library_name = "libcurl"
output_file_path = "../src/wrappers/x86_64-w64-mingw32.jl"

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"
82 changes: 28 additions & 54 deletions gen/generate.jl
Original file line number Diff line number Diff line change
@@ -1,66 +1,40 @@
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(Pkg.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
target = "aarch64-linux-gnu"
for target in JLLEnvs.JLL_ENV_TRIPLES
target == "aarch64-apple-darwin20" && continue

# Generate export statements
open(joinpath(SRC_DIR, "lC_exports_h.jl"), "w+") do exports_file
println(exports_file, "# Generating exports")
@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 = load_options(joinpath(@__DIR__, "configs", "$target.toml"))

# 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




17 changes: 17 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[general]
library_name = "libcurl"
output_file_path = "../src/LibCURL.jl"

use_julia_native_enum_type = true
use_deterministic_symbol = true

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

auto_mutability = true

[codegen.macro]
macro_mode = "basic"
Loading

0 comments on commit e2e0b6f

Please sign in to comment.