Skip to content

Commit f65634e

Browse files
Octogonapusquinnj
andauthored
Generate bindings for each target (#7)
* Generate bindings for each target * Fix JLL compat to be the latest version * Ignore intel itt api symbols * Ignore stdcall for mingw32 * Update to 0.9.14 --------- Co-authored-by: Jacob Quinn <[email protected]>
1 parent 5a4d9b9 commit f65634e

17 files changed

+131166
-197
lines changed

gen/Manifest.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
7272

7373
[[deps.JLLPrefixes]]
7474
deps = ["Artifacts", "Git", "HistoricalStdlibVersions", "Pkg", "Preferences", "SHA", "Scratch"]
75-
git-tree-sha1 = "9343fd4bcb8a4f4f661325e353d70aa00be884c2"
75+
git-tree-sha1 = "c43b83a688b86b33f5b6d8f48d70a41526d845f8"
7676
uuid = "afc68a34-7891-4c5a-9da1-1c62935e7b0d"
77-
version = "0.3.4"
77+
version = "0.3.5"
7878

7979
[[deps.JLLWrappers]]
8080
deps = ["Artifacts", "Preferences"]
@@ -137,9 +137,9 @@ version = "1.2.0"
137137

138138
[[deps.OpenSSL_jll]]
139139
deps = ["Artifacts", "JLLWrappers", "Libdl"]
140-
git-tree-sha1 = "60e3045590bd104a16fefb12836c00c0ef8c7f8c"
140+
git-tree-sha1 = "3da7367955dcc5c54c1ba4d402ccdc09a1a3e046"
141141
uuid = "458c3c95-2e84-50aa-8efc-19380b2a3a95"
142-
version = "3.0.13+0"
142+
version = "3.0.13+1"
143143

144144
[[deps.PCRE2_jll]]
145145
deps = ["Artifacts", "Libdl"]

gen/generator.jl

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,73 @@
11
using Clang.Generators
2+
using Clang.JLLEnvs
23
using JLLPrefixes
4+
import aws_c_common_jll
35

46
cd(@__DIR__)
57

6-
options = load_options(joinpath(@__DIR__, "generator.toml"))
7-
options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "src", "lib.jl")
8-
9-
metas = collect_artifact_metas(["aws_c_common_jll"])
10-
metas_keys = collect(keys(metas))
8+
function remove_itt_symbols!(dag::ExprDAG)
9+
for i in eachindex(dag.nodes)
10+
node = dag.nodes[i]
11+
for expr in get_exprs(node)
12+
node_name = if expr.head == :function
13+
if expr.args[1].args[1] isa Expr # function is Module.name instead of just name
14+
expr.args[1].args[1].args[2]
15+
else
16+
expr.args[1].args[1]
17+
end
18+
elseif expr.head == :struct
19+
if expr.args[2] isa Expr # struct has type parameter
20+
expr.args[2].args[1]
21+
else
22+
expr.args[2]
23+
end
24+
elseif expr.head == :const
25+
expr.args[1].args[1]
26+
end
27+
# remove the node by renaming it to IGNORED, which we include in the generator's ignorelist
28+
if contains(lowercase(string(node_name)), "itt")
29+
dag.nodes[i] = ExprNode(:IGNORED, node.type, node.cursor, node.exprs, node.premature_exprs, node.adj)
30+
end
31+
end
32+
end
33+
return nothing
34+
end
1135

12-
jll_include_dirs = Dict(
13-
"aws_c_common_jll" => ["aws/common"],
14-
)
36+
for target in JLLEnvs.JLL_ENV_TRIPLES
37+
if target == "i686-w64-mingw32"
38+
# aws_c_common_jll does not support i686 windows https://github.com/JuliaPackaging/Yggdrasil/blob/bbab3a916ae5543902b025a4a873cf9ee4a7de68/A/aws_c_common/build_tarballs.jl#L48-L49
39+
continue
40+
end
41+
options = load_options(joinpath(@__DIR__, "generator.toml"))
42+
options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "lib", "$target.jl")
1543

16-
# add compiler flags, e.g. "-DXXXXXXXXX"
17-
args = get_default_args() # Note you must call this function firstly and then append your own flags
18-
header_dirs = String[]
44+
header_dirs = []
45+
args = get_default_args(target)
46+
inc = JLLEnvs.get_pkg_include_dir(aws_c_common_jll, target)
47+
push!(args, "-I$inc")
48+
push!(header_dirs, inc)
1949

20-
for (jll_name, include_dirs) in collect(jll_include_dirs)
21-
meta_key = metas_keys[findfirst(it -> it.name == jll_name, metas_keys)]
22-
meta = metas[meta_key]
23-
if length(meta["paths"]) != 1
24-
error("not sure what to do with these paths", meta)
25-
end
26-
path = meta["paths"][1]
27-
push!(args, "-I$(joinpath(path, "include"))")
28-
for dir in include_dirs
29-
push!(header_dirs, joinpath(path, "include", dir))
50+
headers = String[]
51+
for header_dir in header_dirs
52+
for (root, dirs, files) in walkdir(header_dir)
53+
for file in files
54+
if endswith(file, ".h")
55+
push!(headers, joinpath(root, file))
56+
end
57+
end
58+
end
3059
end
31-
end
60+
unique!(headers)
3261

33-
headers = String[]
34-
for header_dir in header_dirs, file in readdir(header_dir, join=true)
35-
if endswith(file, ".h")
36-
push!(headers, file)
37-
end
38-
end
62+
ctx = create_context(headers, args, options)
3963

40-
# create context
41-
ctx = create_context(headers, args, options)
64+
# build without printing so we can do custom rewriting
65+
build!(ctx, BUILDSTAGE_NO_PRINTING)
4266

43-
# run generator
44-
build!(ctx)
67+
# the ITT symbols are just for aws-c-common's profiling stuff, we don't need to generate them and they cause
68+
# problems with the generated code
69+
remove_itt_symbols!(ctx.dag)
70+
71+
# print
72+
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
73+
end

gen/generator.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ output_ignorelist = [
1010
"AWS_COMMON_MATH_API",
1111
"AWS_THREAD_ONCE_STATIC_INIT",
1212
"AWS_BUS_ADDRESS_ALL",
13+
"IGNORED",
14+
"STDCALL",
1315
]
1416

1517
auto_mutability = false

0 commit comments

Comments
 (0)