Skip to content

Commit

Permalink
Generate bindings in a cd() do-block
Browse files Browse the repository at this point in the history
This makes it a little easier to use from different directories.
  • Loading branch information
JamesWrigley authored and Gnimuc committed Mar 7, 2024
1 parent 1eb99ce commit 587e429
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions gen/generator.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Clang.Generators
using Clang.LibClang.Clang_jll

cd(@__DIR__)

options = load_options(joinpath(@__DIR__, "generator.toml"))

Expand Down Expand Up @@ -58,42 +57,44 @@ const dependencies = PkgSpec[PkgSpec(; name = "LLVM_full_jll")]

const libdir = joinpath(@__DIR__, "..", "lib")

for (llvm_version, julia_version) in (#=(v"12.0.1", v"1.7"),=#
(v"13.0.1", v"1.8"),
(v"14.0.5", v"1.9"),
(v"15.0.6", v"1.10"),
(v"16.0.6", v"1.11"))
@info "Generating..." llvm_version julia_version
temp_prefix() do prefix
# let prefix = Prefix(mktempdir())
platform = Pkg.BinaryPlatforms.HostPlatform()
platform["llvm_version"] = string(llvm_version.major)
platform["julia_version"] = string(julia_version)
artifact_paths = setup_dependencies(prefix, dependencies, platform; verbose=true)

let options = deepcopy(options)
options["general"]["callback_documentation"] = get_docs
output_file_path = joinpath(libdir, string(llvm_version.major), options["general"]["output_file_path"])
isdir(dirname(output_file_path)) || mkpath(dirname(output_file_path))
options["general"]["output_file_path"] = output_file_path

include_dir = joinpath(destdir(prefix, platform), "include")
libclang_header_dir = joinpath(include_dir, "clang-c")
args = Generators.get_default_args()
push!(args, "-I$include_dir")

headers = detect_headers(libclang_header_dir, args)
ctx = create_context(headers, args, options)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
cd(@__DIR__) do
for (llvm_version, julia_version) in (#=(v"12.0.1", v"1.7"),=#
(v"13.0.1", v"1.8"),
(v"14.0.5", v"1.9"),
(v"15.0.6", v"1.10"),
(v"16.0.6", v"1.11"))
@info "Generating..." llvm_version julia_version
temp_prefix() do prefix
# let prefix = Prefix(mktempdir())
platform = Pkg.BinaryPlatforms.HostPlatform()
platform["llvm_version"] = string(llvm_version.major)
platform["julia_version"] = string(julia_version)
artifact_paths = setup_dependencies(prefix, dependencies, platform; verbose=true)

let options = deepcopy(options)
options["general"]["callback_documentation"] = get_docs
output_file_path = joinpath(libdir, string(llvm_version.major), options["general"]["output_file_path"])
isdir(dirname(output_file_path)) || mkpath(dirname(output_file_path))
options["general"]["output_file_path"] = output_file_path

include_dir = joinpath(destdir(prefix, platform), "include")
libclang_header_dir = joinpath(include_dir, "clang-c")
args = Generators.get_default_args()
push!(args, "-I$include_dir")

headers = detect_headers(libclang_header_dir, args)
ctx = create_context(headers, args, options)

# build without printing so we can do custom rewriting
build!(ctx, BUILDSTAGE_NO_PRINTING)

rewrite!(ctx.dag)

# print
build!(ctx, BUILDSTAGE_PRINTING_ONLY)
end

cleanup_dependencies(prefix, artifact_paths, platform)
end

cleanup_dependencies(prefix, artifact_paths, platform)
end
end

0 comments on commit 587e429

Please sign in to comment.