|
1 | 1 | using Clang.Generators |
| 2 | +using Clang.JLLEnvs |
2 | 3 | using JLLPrefixes |
| 4 | +import aws_c_common_jll |
3 | 5 |
|
4 | 6 | cd(@__DIR__) |
5 | 7 |
|
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 |
11 | 35 |
|
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") |
15 | 43 |
|
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) |
19 | 49 |
|
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 |
30 | 59 | end |
31 | | -end |
| 60 | + unique!(headers) |
32 | 61 |
|
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) |
39 | 63 |
|
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) |
42 | 66 |
|
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 |
0 commit comments