Meta: Add serenity toolchain to gn build
This commit is contained in:
parent
f8e1544f41
commit
f4e37c8ad4
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/SerenityOS/serenity/commit/f4e37c8ad4 Pull-request: https://github.com/SerenityOS/serenity/pull/20209
5 changed files with 77 additions and 11 deletions
Meta/gn/build
|
@ -142,6 +142,7 @@ config("compiler_defaults") {
|
|||
if (sysroot != "") {
|
||||
if (current_os != "mac" && current_os != "android") {
|
||||
cflags += [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
|
||||
ldflags += [ "--sysroot=" + rebase_path(sysroot, root_build_dir) ]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
31
Meta/gn/build/serenity_target.gni
Normal file
31
Meta/gn/build/serenity_target.gni
Normal file
|
@ -0,0 +1,31 @@
|
|||
declare_args() {
|
||||
# Serenity architecture to build for
|
||||
serenity_arch = "x86_64"
|
||||
|
||||
# Serenity compiler to use, Clang or GNU
|
||||
serenity_toolchain = "GNU"
|
||||
}
|
||||
|
||||
if (serenity_toolchain == "GNU") {
|
||||
toolchain_root =
|
||||
rebase_path("//Toolchain/Local/$serenity_arch/", root_build_dir)
|
||||
toolchain_bin = toolchain_root + "bin/"
|
||||
|
||||
serenity_cc = toolchain_bin + serenity_arch + "-pc-serenity-gcc"
|
||||
serenity_cxx = toolchain_bin + serenity_arch + "-pc-serenity-g++"
|
||||
serenity_ld = serenity_cxx
|
||||
serenity_nm = toolchain_bin + serenity_arch + "-pc-serenity-nm"
|
||||
serenity_objcopy = toolchain_bin + serenity_arch + "-pc-serenity-objcopy"
|
||||
serenity_compiler_version = "13.1.0"
|
||||
} else {
|
||||
assert(serenity_toolchain == "Clang",
|
||||
"Expected GNU or Clang for serenity_toolchain")
|
||||
toolchain_root = rebase_path("//Toolchain/Local/clang/", root_build_dir)
|
||||
toolchain_bin = toolchain_root + "bin/"
|
||||
serenity_cc = toolchain_bin + serenity_arch + "-pc-serenity-clang"
|
||||
serenity_cxx = toolchain_bin + serenity_arch + "-pc-serenity-clang++"
|
||||
serenity_ld = serenity_cxx
|
||||
serenity_nm = toolchain_bin + "llvm-nm"
|
||||
serenity_objcopy = toolchain_bin + "llvm-objcopy"
|
||||
serenity_compiler_version = "16"
|
||||
}
|
|
@ -1,4 +1,7 @@
|
|||
declare_args() {
|
||||
# Path of sysroot to use.
|
||||
sysroot = ""
|
||||
if (current_os == "serenity") {
|
||||
sysroot = "$root_build_dir/Root"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import("//Meta/gn/build/serenity_target.gni")
|
||||
import("//Meta/gn/build/toolchain/compiler.gni")
|
||||
|
||||
unix_copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
|
||||
|
||||
template("unix_toolchain") {
|
||||
|
@ -10,6 +13,13 @@ template("unix_toolchain") {
|
|||
forward_variables_from(invoker.toolchain_args, "*")
|
||||
forward_variables_from(invoker, "*")
|
||||
|
||||
not_needed([
|
||||
"current_cpu",
|
||||
"cc",
|
||||
"is_clang",
|
||||
"use_lld",
|
||||
])
|
||||
|
||||
tool("cc") {
|
||||
depfile = "{{output}}.d"
|
||||
command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}"
|
||||
|
@ -55,10 +65,12 @@ template("unix_toolchain") {
|
|||
description = "AR {{output}}"
|
||||
outputs = [ "{{output_dir}}/{{target_output_name}}.a" ]
|
||||
output_prefix = "lib"
|
||||
if (current_os != "serenity") {
|
||||
if (current_os == "serenity") {
|
||||
default_output_dir = "{{target_out_dir}}"
|
||||
} else {
|
||||
output_prefix = "liblagom-"
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
|
||||
# Make these apply to all tools below.
|
||||
|
@ -77,10 +89,12 @@ template("unix_toolchain") {
|
|||
description = "SOLINK $outfile"
|
||||
outputs = [ outfile ]
|
||||
output_prefix = "lib"
|
||||
if (current_os != "serenity") {
|
||||
if (current_os == "serenity") {
|
||||
default_output_dir = "{{target_out_dir}}"
|
||||
} else {
|
||||
output_prefix = "liblagom-"
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
|
||||
tool("solink_module") {
|
||||
|
@ -94,10 +108,12 @@ template("unix_toolchain") {
|
|||
}
|
||||
description = "SOLINK $outfile"
|
||||
outputs = [ outfile ]
|
||||
if (current_os != "serenity") {
|
||||
if (current_os == "serenity") {
|
||||
default_output_dir = "{{target_out_dir}}"
|
||||
} else {
|
||||
output_prefix = "lagom-"
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
default_output_dir = "{{root_out_dir}}/lib"
|
||||
}
|
||||
|
||||
tool("link") {
|
||||
|
@ -110,9 +126,13 @@ template("unix_toolchain") {
|
|||
description = "LINK $outfile"
|
||||
outputs = [ outfile ]
|
||||
|
||||
# Setting this allows targets to override the default executable output by
|
||||
# setting output_dir.
|
||||
default_output_dir = "{{root_out_dir}}/bin"
|
||||
if (current_os == "serenity") {
|
||||
# Setting this allows targets to override the default executable output by
|
||||
# setting output_dir.
|
||||
default_output_dir = "{{target_out_dir}}"
|
||||
} else {
|
||||
default_output_dir = "{{root_out_dir}}/bin"
|
||||
}
|
||||
}
|
||||
|
||||
tool("copy") {
|
||||
|
@ -157,4 +177,15 @@ unix_toolchain("unix") {
|
|||
cxx = host_cxx
|
||||
}
|
||||
}
|
||||
# Note: For serenity, we can override cc and cxx etc in toolchain_args
|
||||
|
||||
unix_toolchain("serenity") {
|
||||
cc = serenity_cc
|
||||
cxx = serenity_cxx
|
||||
ld = serenity_ld
|
||||
toolchain_args = {
|
||||
current_os = "serenity"
|
||||
current_cpu = serenity_arch
|
||||
is_clang = serenity_toolchain == "Clang"
|
||||
use_lld = is_clang
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
declare_args() {
|
||||
# Set to true when host compiler is clang so that clang flags will be passed to it
|
||||
is_clang = host_os == "mac"
|
||||
is_clang = current_os == "mac"
|
||||
|
||||
# Enable setting -fuse-ld and other flags for using the lld linker.
|
||||
# Should not be set on macOS when using the default system compiler.
|
||||
|
|
Loading…
Add table
Reference in a new issue