-
Notifications
You must be signed in to change notification settings - Fork 14
/
generator.jl
executable file
·104 lines (89 loc) · 4.16 KB
/
generator.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using Clang.Generators
using Clang.Generators.JLLEnvs
import Vulkan_Headers_jll
using Wayland_jll
using Xorg_libxcb_jll
using Xorg_xorgproto_jll
using Xorg_libX11_jll
using Xorg_libXrandr_jll
using Xorg_libXrender_jll
cd(@__DIR__)
# get include directory & vulkan.h
VK_INCLUDE_BASE = joinpath(Vulkan_Headers_jll.artifact_dir, "include")
VK_INCLUDE = joinpath(VK_INCLUDE_BASE, "vulkan")
VK_HEADERS = [joinpath(VK_INCLUDE, "vulkan.h")]
# config extensions for different platforms
# X-ref: https://github.com/SaschaWillems/Vulkan/blob/master/CMakeLists.txt
VK_LINUX_EXTENSION_COMMON = [
# "-DVK_USE_PLATFORM_DIRECTFB_EXT", # no JLL package
"-DVK_USE_PLATFORM_WAYLAND_KHR",
"-DVK_USE_PLATFORM_XCB_KHR",
"-DVK_USE_PLATFORM_XLIB_KHR",
"-DVK_USE_PLATFORM_XLIB_XRANDR_EXT",
]
VK_MACOS_EXTENSION_COMMON = ["-DVK_USE_PLATFORM_MACOS_MVK", "-DVK_USE_PLATFORM_METAL_EXT"]
VK_WIN_EXTENSION_COMMON = ["-DVK_USE_PLATFORM_WIN32_KHR"]
VK_EXTENSIONS_MAP = Dict(
# "aarch64-apple-darwin20" => vcat(VK_MACOS_EXTENSION_COMMON, "-DVK_USE_PLATFORM_DIRECTFB_EXT"),
# "x86_64-apple-darwin14" => vcat(VK_MACOS_EXTENSION_COMMON, "-DVK_USE_PLATFORM_DIRECTFB_EXT"),
"aarch64-apple-darwin20" => VK_MACOS_EXTENSION_COMMON,
"x86_64-apple-darwin14" => VK_MACOS_EXTENSION_COMMON,
"i686-w64-mingw32" => VK_WIN_EXTENSION_COMMON,
"x86_64-w64-mingw32" => VK_WIN_EXTENSION_COMMON,
# "aarch64-linux-gnu" => vcat(VK_LINUX_EXTENSION_COMMON, "-DVK_USE_PLATFORM_FUCHSIA"),
# "aarch64-linux-musl" => vcat(VK_LINUX_EXTENSION_COMMON, "-DVK_USE_PLATFORM_FUCHSIA"),
"aarch64-linux-gnu" => VK_LINUX_EXTENSION_COMMON,
"aarch64-linux-musl" => VK_LINUX_EXTENSION_COMMON,
"armv7l-linux-gnueabihf" => VK_LINUX_EXTENSION_COMMON,
"armv7l-linux-musleabihf" => VK_LINUX_EXTENSION_COMMON,
"x86_64-linux-gnu" => VK_LINUX_EXTENSION_COMMON,
"x86_64-linux-musl" => VK_LINUX_EXTENSION_COMMON,
"i686-linux-gnu" => VK_LINUX_EXTENSION_COMMON,
"i686-linux-musl" => VK_LINUX_EXTENSION_COMMON,
"powerpc64le-linux-gnu" => VK_LINUX_EXTENSION_COMMON,
"x86_64-unknown-freebsd" => ["-DVK_USE_PLATFORM_XCB_KHR", "-DVK_USE_PLATFORM_XLIB_KHR", "-DVK_USE_PLATFORM_XLIB_XRANDR_EXT"],
)
for target in JLLEnvs.JLL_ENV_TRIPLES
@info "processing $target"
# programmatically add options
options = Dict{String,Any}(
"general" => Dict{String,Any}(),
"codegen" => Dict{String,Any}(),
)
general, codegen = options["general"], options["codegen"]
general["library_name"] = "libvulkan"
general["output_file_path"] = joinpath(@__DIR__, "..", "lib", "$target.jl")
general["use_deterministic_symbol"] = true
general["print_using_CEnum"] = false
general["printer_blacklist"] = [
"VKAPI_PTR",
"VKAPI_CALL",
]
general["add_fptr_methods"] = true
general["extract_c_comment_style"] = "doxygen"
general["struct_field_comment_style"] = "outofline"
general["enumerator_comment_style"] = "outofline"
codegen["add_record_constructors"] = true
codegen["union_single_constructor"] = true
codegen["opaque_as_mutable_struct"] = false
# add compiler flags
args = get_default_args(target)
push!(args, "-I$VK_INCLUDE")
wayland_inc = JLLEnvs.get_pkg_include_dir(Wayland_jll, target)
!isempty(wayland_inc) && push!(args, "-isystem$wayland_inc")
xcb_inc = JLLEnvs.get_pkg_include_dir(Xorg_libxcb_jll, target)
!isempty(xcb_inc) && push!(args, "-isystem$xcb_inc")
xlibx_inc = JLLEnvs.get_pkg_include_dir(Xorg_xorgproto_jll, target)
!isempty(xlibx_inc) && push!(args, "-isystem$xlibx_inc")
xlib_inc = JLLEnvs.get_pkg_include_dir(Xorg_libX11_jll, target)
!isempty(xlib_inc) && push!(args, "-isystem$xlib_inc")
xlibXrandr_inc = JLLEnvs.get_pkg_include_dir(Xorg_libXrandr_jll, target)
!isempty(xlibXrandr_inc) && push!(args, "-isystem$xlibXrandr_inc")
xlibXrender_inc = JLLEnvs.get_pkg_include_dir(Xorg_libXrender_jll, target)
!isempty(xlibXrender_inc) && push!(args, "-isystem$xlibXrender_inc")
append!(args, VK_EXTENSIONS_MAP[target])
# add header directory to detect `vk_video` headers
push!(args, "-I$VK_INCLUDE_BASE")
ctx = create_context(VK_HEADERS, args, options)
build!(ctx)
end