Skip to content

Commit

Permalink
Fix generator handling of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Octogonapus committed May 1, 2024
1 parent b241946 commit afcc994
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
8 changes: 7 additions & 1 deletion gen/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.2"
manifest_format = "2.0"
project_hash = "ca818dcfd9f2d48838a2ea582942e9db6ef31f6a"
project_hash = "352d79169fdab460bd7e762ac5ffa4e96f3c880d"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
Expand Down Expand Up @@ -82,6 +82,12 @@ git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca"
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
version = "1.5.0"

[[deps.LibAwsCommon]]
deps = ["CEnum", "aws_c_common_jll"]
git-tree-sha1 = "d8705f05415a487369d5bbfb2ca149c72ffb5609"
uuid = "c6e421ba-b5f8-4792-a1c4-42948de3ed9d"
version = "1.0.0"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
Expand Down
1 change: 1 addition & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JLLPrefixes = "afc68a34-7891-4c5a-9da1-1c62935e7b0d"
LibAwsCommon = "c6e421ba-b5f8-4792-a1c4-42948de3ed9d"
aws_c_cal_jll = "70f11efc-bab2-57f1-b0f3-22aad4e67c4b"
aws_c_common_jll = "73048d1d-b8c4-5092-a58d-866c5e8d1e50"

Expand Down
41 changes: 23 additions & 18 deletions gen/generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ using Clang.Generators
using Clang.JLLEnvs
using JLLPrefixes
import aws_c_common_jll, aws_c_cal_jll
using LibAwsCommon

cd(@__DIR__)

const refs_to_remove = []

# This is called if the docs generated from the extract_c_comment_style method did not generate any lines.
# We need to generate at least some docs so that cross-references work with Documenter.jl.
function get_docs(node, docs)
Expand All @@ -21,19 +20,6 @@ function get_docs(node, docs)
return ["Documentation not found."]
end

# remove references to things which don't exist because it causes Documenter.jl's cross_references check to fail
for ref in refs_to_remove
for doci in eachindex(docs)
docs[doci] = replace(docs[doci], "[`$ref`](@ref)" => "`$ref`")
end
end

# # fix other random stuff
# for doci in eachindex(docs)
# # fix some code that gets bogus references inserted
# 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. }`")
# end

return docs
end

Expand All @@ -42,6 +28,21 @@ function should_skip_target(target)
return target == "i686-w64-mingw32"
end

const deps_jlls = [aws_c_common_jll]
const deps = [LibAwsCommon]
const deps_names = sort(collect(Iterators.flatten(names.(deps))))

# clang can emit code for forward declarations of structs defined in our dependencies. we need to skip those, otherwise
# we'll have duplicate struct definitions.
function skip_nodes_in_dependencies!(dag::ExprDAG)
replace!(get_nodes(dag)) do node
if insorted(node.id, deps_names)
return ExprNode(node.id, Generators.Skip(), node.cursor, Expr[], node.adj)
end
return node
end
end

# download toolchains in parallel
Threads.@threads for target in JLLEnvs.JLL_ENV_TRIPLES
if should_skip_target(target)
Expand All @@ -59,8 +60,10 @@ for target in JLLEnvs.JLL_ENV_TRIPLES
options["general"]["callback_documentation"] = get_docs

args = get_default_args(target)
inc = JLLEnvs.get_pkg_include_dir(aws_c_common_jll, target)
push!(args, "-isystem$inc")
for dep in deps_jlls
inc = JLLEnvs.get_pkg_include_dir(dep, target)
push!(args, "-isystem$inc")
end

header_dirs = []
inc = JLLEnvs.get_pkg_include_dir(aws_c_cal_jll, target)
Expand All @@ -80,5 +83,7 @@ for target in JLLEnvs.JLL_ENV_TRIPLES
unique!(headers)

ctx = create_context(headers, args, options)
build!(ctx)
build!(ctx, BUILDSTAGE_NO_PRINTING)
skip_nodes_in_dependencies!(ctx.dag)
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
end

0 comments on commit afcc994

Please sign in to comment.