diff --git a/Meta/gn/build/BUILD.gn b/Meta/gn/build/BUILD.gn index 1ee4742465..5d65eae68e 100644 --- a/Meta/gn/build/BUILD.gn +++ b/Meta/gn/build/BUILD.gn @@ -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) ] } } diff --git a/Meta/gn/build/serenity_target.gni b/Meta/gn/build/serenity_target.gni new file mode 100644 index 0000000000..4a4bcfadcb --- /dev/null +++ b/Meta/gn/build/serenity_target.gni @@ -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" +} diff --git a/Meta/gn/build/sysroot.gni b/Meta/gn/build/sysroot.gni index b1b4e74cea..b9e2dd357e 100644 --- a/Meta/gn/build/sysroot.gni +++ b/Meta/gn/build/sysroot.gni @@ -1,4 +1,7 @@ declare_args() { # Path of sysroot to use. sysroot = "" + if (current_os == "serenity") { + sysroot = "$root_build_dir/Root" + } } diff --git a/Meta/gn/build/toolchain/BUILD.gn b/Meta/gn/build/toolchain/BUILD.gn index 3fec474573..82a937fa26 100644 --- a/Meta/gn/build/toolchain/BUILD.gn +++ b/Meta/gn/build/toolchain/BUILD.gn @@ -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 + } +} diff --git a/Meta/gn/build/toolchain/compiler.gni b/Meta/gn/build/toolchain/compiler.gni index 5608161186..66d41343b2 100644 --- a/Meta/gn/build/toolchain/compiler.gni +++ b/Meta/gn/build/toolchain/compiler.gni @@ -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.