Skip to content

Commit c16ffda

Browse files
Adjust generated code to work better with cross-references and be more complete (#8)
* Add docs * update clang for bugfix * Regenerate bindings * Fix base ref for PR triggers * Download toolchains in parallel * fix * change bindings to check the generator PR works * Regenerate bindings (#9) Co-authored-by: Octogonapus <[email protected]> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c3807f0 commit c16ffda

20 files changed

+12945
-1261
lines changed

.github/workflows/generate_bindings.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@ jobs:
2929
- name: Run the generator
3030
run: ./gen/generate.sh
3131

32-
- name: Create Pull Request
32+
- name: Create Pull Request (on push)
33+
if: ${{ github.event_name == 'push' }}
3334
uses: peter-evans/create-pull-request@v6
3435
with:
3536
commit-message: "Regenerate bindings"
3637
title: "Regenerate bindings"
3738
reviewers: |
3839
quinnj
3940
Octogonapus
41+
42+
- name: Create Pull Request (on PR)
43+
if: ${{ github.event_name == 'pull_request' }}
44+
uses: peter-evans/create-pull-request@v6
45+
with:
46+
base: ${{ github.head_ref }}
47+
commit-message: "Regenerate bindings"
48+
title: "Regenerate bindings"
49+
reviewers: |
50+
quinnj
51+
Octogonapus

docs/make.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ makedocs(;
1111
prettyurls=get(ENV, "CI", "false") == "true",
1212
canonical="https://github.com/JuliaServices/LibAwsCommon.jl",
1313
assets=String[],
14+
size_threshold=2_000_000, # 2 MB, we generate about 1 MB page
15+
size_threshold_warn=2_000_000,
1416
),
1517
pages=["Home" => "index.md"],
1618
)

gen/Manifest.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.10.2"
44
manifest_format = "2.0"
5-
project_hash = "17529965341e648e57dcbc863dd11933859fd679"
5+
project_hash = "981bed63f0072e15b9d8cfedf2a309eaddd66050"
66

77
[[deps.ArgTools]]
88
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
@@ -21,9 +21,9 @@ version = "0.5.0"
2121

2222
[[deps.Clang]]
2323
deps = ["CEnum", "Clang_jll", "Downloads", "Pkg", "TOML"]
24-
git-tree-sha1 = "846054622cb22aa63b5d51b5d84ec04b42d4d587"
24+
git-tree-sha1 = "2397d5da17ba4970f772a9888b208a0a1d77eb5d"
2525
uuid = "40e3b903-d033-50b4-a0cc-940c62c95e31"
26-
version = "0.17.8"
26+
version = "0.18.3"
2727

2828
[[deps.Clang_jll]]
2929
deps = ["Artifacts", "JLLWrappers", "Libdl", "TOML", "Zlib_jll", "libLLVM_jll"]
@@ -57,9 +57,9 @@ version = "1.3.1"
5757

5858
[[deps.Git_jll]]
5959
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "Libiconv_jll", "OpenSSL_jll", "PCRE2_jll", "Zlib_jll"]
60-
git-tree-sha1 = "12945451c5d0e2d0dca0724c3a8d6448b46bbdf9"
60+
git-tree-sha1 = "d18fb8a1f3609361ebda9bf029b60fd0f120c809"
6161
uuid = "f8c6e375-362e-5223-8a59-34ff63f689eb"
62-
version = "2.44.0+1"
62+
version = "2.44.0+2"
6363

6464
[[deps.HistoricalStdlibVersions]]
6565
git-tree-sha1 = "c8b04a26eaa706b4da6968dfc27ae2d030547cba"

gen/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ JLLPrefixes = "afc68a34-7891-4c5a-9da1-1c62935e7b0d"
44
aws_c_common_jll = "73048d1d-b8c4-5092-a58d-866c5e8d1e50"
55

66
[compat]
7-
Clang = "0.17"
7+
Clang = "0.18.3"
88
JLLPrefixes = "0.3"
99
aws_c_common_jll = "=0.9.14"

gen/generate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
dir=$(dirname "$0")
33
julia --project="$dir" -e 'using Pkg; Pkg.instantiate()'
4-
julia --project="$dir" "$dir/generator.jl"
4+
julia --project="$dir" -t auto "$dir/generator.jl"

gen/generator.jl

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,95 @@ import aws_c_common_jll
55

66
cd(@__DIR__)
77

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
8+
function node_is_ignored(node)
9+
for expr in get_exprs(node)
10+
node_name = if expr.head == :function
11+
if expr.args[1].args[1] isa Expr # function is Module.name instead of just name
12+
expr.args[1].args[1].args[2]
13+
else
2514
expr.args[1].args[1]
2615
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)
16+
elseif expr.head == :struct
17+
if expr.args[2] isa Expr # struct has type parameter
18+
expr.args[2].args[1]
19+
else
20+
expr.args[2]
3021
end
22+
elseif expr.head == :const
23+
expr.args[1].args[1]
24+
end
25+
return contains(lowercase(string(node_name)), "itt")
26+
end
27+
return false
28+
end
29+
30+
function remove_itt_symbols!(dag::ExprDAG)
31+
for i in eachindex(dag.nodes)
32+
# remove the node by renaming it to IGNORED, which we include in the generator's ignorelist
33+
node = dag.nodes[i]
34+
if node_is_ignored(node)
35+
dag.nodes[i] = ExprNode(:IGNORED, node.type, node.cursor, node.exprs, node.premature_exprs, node.adj)
3136
end
3237
end
3338
return nothing
3439
end
3540

41+
const refs_to_remove = ("AWS_CONTAINER_OF", "AWS_STATIC_STRING_FROM_LITERAL",)
42+
43+
# This is called if the docs generated from the extract_c_comment_style method did not generate any lines.
44+
# We need to generate at least some docs so that cross-references work with Documenter.jl.
45+
function get_docs(node, docs)
46+
# The macro node types (except for MacroDefault) seem to not generate code, but they will still emit docs and then
47+
# you end up with docs stacked on top of each other, which is a Julia LoadError.
48+
if node.type isa Generators.AbstractMacroNodeType && !(node.type isa Generators.MacroDefault)
49+
return String[]
50+
end
51+
52+
# don't generate empty docs because it makes Documenter.jl mad
53+
if isempty(docs)
54+
return ["Documentation not found."]
55+
end
56+
57+
# remove references to things which don't exist because it causes Documenter.jl's cross_references check to fail
58+
for ref in refs_to_remove
59+
for doci in eachindex(docs)
60+
docs[doci] = replace(docs[doci], "[`$ref`](@ref)" => "`$ref`")
61+
end
62+
end
63+
64+
# fix other random stuff
65+
for doci in eachindex(docs)
66+
# fix some code that gets bogus references inserted
67+
docs[doci] = replace(docs[doci], "for (struct [`aws_hash_iter`](@ref) iter = [`aws_hash_iter_begin`](@ref)(&map); ![`aws_hash_iter_done`](@ref)(&iter); [`aws_hash_iter_next`](@ref)(&iter)) { const key\\_type key = *(const key\\_type *)iter.element.key; value\\_type value = *(value\\_type *)iter.element.value; // etc. }" => "`for (struct aws_hash_iter iter = aws_hash_iter_begin(&map); !aws_hash_iter_done(&iter); aws_hash_iter_next(&iter)) { const key\\_type key = *(const key\\_type *)iter.element.key; value\\_type value = *(value\\_type *)iter.element.value; // etc. }`")
68+
end
69+
70+
return docs
71+
end
72+
73+
function should_skip_target(target)
74+
# 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
75+
return target == "i686-w64-mingw32"
76+
end
77+
78+
# download toolchains in parallel
79+
Threads.@threads for target in JLLEnvs.JLL_ENV_TRIPLES
80+
if should_skip_target(target)
81+
continue
82+
end
83+
get_default_args(target) # downloads the toolchain
84+
end
85+
3686
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
87+
if should_skip_target(target)
3988
continue
4089
end
4190
options = load_options(joinpath(@__DIR__, "generator.toml"))
4291
options["general"]["output_file_path"] = joinpath(@__DIR__, "..", "lib", "$target.jl")
92+
options["general"]["callback_documentation"] = get_docs
4393

4494
header_dirs = []
4595
args = get_default_args(target)
96+
push!(args, "-fparse-all-comments")
4697
inc = JLLEnvs.get_pkg_include_dir(aws_c_common_jll, target)
4798
push!(args, "-I$inc")
4899
push!(header_dirs, inc)

0 commit comments

Comments
 (0)