lwjgl/Tinsel.lua

286 lines
7.8 KiB
Lua

local toolchain = path(ENV.JAVA_HOME)
local src_java = path("src/java")
local src_tmpl = path("src/templates")
local src_native = path("src/native")
local libs = path("libs")
local common_srcs = table.freeze({
-- common
"org/lwjgl/PointerWrapper.java",
"org/lwjgl/PointerWrapperAbstract.java",
"org/lwjgl/PointerBuffer.java",
-- opencl
"org/lwjgl/opencl/CLPlatform.java",
"org/lwjgl/opencl/CLDevice.java",
"org/lwjgl/opencl/CLContext.java",
"org/lwjgl/opencl/CLCommandQueue.java",
"org/lwjgl/opencl/CLMem.java",
"org/lwjgl/opencl/CLBuildProgramCallback.java",
"org/lwjgl/opencl/CLCompileProgramCallback.java",
"org/lwjgl/opencl/CLContextCallback.java",
"org/lwjgl/opencl/CLEventCallback.java",
"org/lwjgl/opencl/CLLinkProgramCallback.java",
"org/lwjgl/opencl/CLMemObjectDestructorCallback.java",
"org/lwjgl/opencl/CLPrintfCallback.java",
"org/lwjgl/opencl/CLProgramCallback.java",
"org/lwjgl/opencl/CLNativeKernel.java",
"org/lwjgl/opencl/CLFunctionAddress.java",
-- opengl
"org/lwjgl/opengl/GLSync.java",
"org/lwjgl/opengl/AMDDebugOutputCallback.java",
"org/lwjgl/opengl/ARBDebugOutputCallback.java",
"org/lwjgl/opengl/KHRDebugCallback.java",
-- opengles
"org/lwjgl/opengles/EGLImageOES.java",
"org/lwjgl/opengles/KHRDebugCallback.java",
})
common_srcs = map(common_srcs, function(p) return rootedpath(src_java, src_java .. p) end)
local sp = src_java.value
local compile_generators = task("compile_generators", function(env)
local java = require("!java")
java = java.withToolchain(toolchain)
local srcs_gen = walk_rootedpath{path = src_java .. "org/lwjgl/util/generator"}
-- compile common classes required by the generators
local out_common = java.compileJar(env:derive(), {
implicit = true,
srcs = common_srcs,
class_path = files({libs .. "unfettered.jar"}),
extra_args = {
"--source-path", sp,
},
})
-- compile the generators
local out_gen = java.compileJar(env:derive(), {
srcs = srcs_gen,
class_path = files({out_common.classes}),
extra_args = {
"--source-path", sp,
},
-- TODO: need to track source path
--__source_path = files()
})
return {out_common.classes, out_gen.classes}
end)
local generate = export(task("generate", function(env)
local java = require("!java")
java = java.withToolchain(toolchain)
-- all generator sources
local srcs_openal = walk_rootedpath{path = src_tmpl .. "org/lwjgl/openal"}
local srcs_opengl = walk_rootedpath{path = src_tmpl .. "org/lwjgl/opengl"}
local srcs_opencl = walk_rootedpath{path = src_tmpl .. "org/lwjgl/opencl"}
local srcs_opengles = walk_rootedpath{path = src_tmpl .. "org/lwjgl/opengles"}
local class_path = files(compile_generators())
local dest_props_java = {"genJavaPath"}
local dest_props_native = {"genNativePath"}
local function with_dest_props(input, dest_props)
input = table.clone(input)
input.dest_props = dest_props
return input
end
local function compile(input)
input.class_path = class_path
local env = env:derive()
return async(function()
local output = java.compile(env, input)
return map_rootedpath(output.root, output.files)
end)
--local output = java.compile(env, input)
--output = map_rootedpath(output.root, output.files)
--return async(function() return output end)
end
local gen_openal = {
srcs = srcs_openal,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.GeneratorProcessor",
"-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap",
"-Anovalidate=true",
},
}
local gen_openal_java = {compile(with_dest_props(gen_openal, dest_props_java))}
local gen_openal_native = compile(with_dest_props(gen_openal, dest_props_native))
local gen_opengl = {
srcs = srcs_opengl,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.GeneratorProcessor",
"-Acontextspecific",
"-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap",
"-Anovalidate=true",
},
}
local gen_opengl_java = {
compile(with_dest_props(gen_opengl, dest_props_java)),
compile(with_dest_props({
srcs = srcs_opengl,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessor",
"-Acontextspecific",
}
}, dest_props_java)),
compile(with_dest_props({
srcs = srcs_opengl,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.opengl.GLGeneratorProcessor",
"-Acontextspecific",
}
}, dest_props_java)),
}
local gen_opengl_native = compile(with_dest_props(gen_opengl, dest_props_native))
local gen_opencl = {
srcs = srcs_opencl,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.GeneratorProcessor",
"-Acontextspecific",
"-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap",
"-Anovalidate=true",
},
}
local gen_opencl_java = {
compile(with_dest_props(gen_opencl, dest_props_java)),
compile(with_dest_props({
srcs = srcs_opencl,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.opencl.CLGeneratorProcessor",
"-Acontextspecific",
}
}, dest_props_java)),
}
local gen_opencl_native = compile(with_dest_props(gen_opencl, dest_props_native))
local gen_opengles = {
srcs = srcs_opengles,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.GeneratorProcessor",
"-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap",
"-Anovalidate=true",
},
}
local gen_opengles_java = {
compile(with_dest_props(gen_opengles, dest_props_java)),
compile(with_dest_props({
srcs = srcs_opengles,
extra_args = {
"--source-path", sp,
"-proc:only",
"-processor",
"org.lwjgl.util.generator.opengl.GLESGeneratorProcessor",
}
}, dest_props_java)),
}
local gen_opengles_native = compile(with_dest_props(gen_opengles, dest_props_native))
local gen_java = table.concat(gen_openal_java, gen_opengl_java, gen_opencl_java, gen_opengles_java)
local gen_native = {
gen_openal_native,
gen_opengl_native,
gen_opencl_native,
gen_opengles_native,
}
local gen_java, gen_native = await(async(function()
return table.concat(await(gen_java))
end), async(function()
return table.concat(await(gen_native))
end))
return { java = gen_java, native = gen_native }
end))
compile_java = export(task("compile_java", function(env)
local java = require("!java")
java = java.withToolchain(toolchain)
local srcs_root = src_java .. "org/lwjgl"
local ignore_a = srcs_root.value .. "/util/generator"
local ignore_b = srcs_root.value .. "/util/test"
local ignore_c = srcs_root.value .. "/test"
local ignore_d = srcs_root.value .. "/util/mapped"
local srcs = table.clone(walk_rootedpath{path = srcs_root})
filter(srcs, function(path)
local p = path.path.value
return not p:startswith(ignore_a, ignore_b, ignore_c, ignore_d)
end)
table.insert(srcs, rootedpath(path("src/module"), path("src/module") .. "module-info.java"))
push_all(srcs, generate().java)
table.freeze(srcs)
return java.compileJar(env:derive(), {
srcs = srcs,
class_path = files({
libs .. "unfettered.jar",
libs .. "jinput.jar",
libs .. "AppleJavaExtensions.jar",
}),
extra_args = {
"--add-reads", "lwjgl=ALL-UNNAMED",
},
})
end))
local build_symbol_list = task("build_symbol_list", function(env, srcs: {InputFile})
env:memoize(srcs, function(srcs, output)
local args = map(srcs, function(src) return src.path.value end)
local output = exec_with_output("nm", "-j", "-g", table.unpack(args))
check_status(output)
local pat = compile_regex("^_J(ava|NI|avaCritical)_.*$", {multi_line = true});
local buf = ""
pat.for_each_match(output.stdout, function(match)
buf ..= match .. "\n"
end)
intrinsic.io.write_file(output, buf)
end)
end)