Squash commits for public release
This commit is contained in:
123
build/libs/BUILD.gn
Normal file
123
build/libs/BUILD.gn
Normal file
@@ -0,0 +1,123 @@
|
||||
lib_c_flags = [
|
||||
"-ffreestanding",
|
||||
"-Werror",
|
||||
"-Wno-address-of-packed-member",
|
||||
]
|
||||
|
||||
if (userland_symbols) {
|
||||
lib_c_flags += [ "-ggdb" ]
|
||||
}
|
||||
|
||||
if (optimize) {
|
||||
lib_c_flags += [ "-Os" ]
|
||||
}
|
||||
|
||||
lib_cc_flags = [
|
||||
"-std=c++2a",
|
||||
"-fno-sized-deallocation",
|
||||
"-fno-exceptions",
|
||||
"-D_LIBCXX_BUILD_XOS_EXTENSIONS",
|
||||
]
|
||||
|
||||
lib_objcc_flags = lib_cc_flags + [
|
||||
"-Wno-nullability-completeness",
|
||||
"-Wno-deprecated-objc-isa-usage",
|
||||
"-Wno-objc-root-class",
|
||||
"-Wno-cast-of-sel-type",
|
||||
"-fno-objc-exceptions",
|
||||
"-fno-objc-arc",
|
||||
"-fno-unwind-tables",
|
||||
]
|
||||
|
||||
lib_asm_flags = []
|
||||
|
||||
if (device_type == "desktop") {
|
||||
lib_c_flags += [ "-DTARGET_DESKTOP" ]
|
||||
}
|
||||
if (device_type == "mobile") {
|
||||
lib_c_flags += [ "-DTARGET_MOBILE" ]
|
||||
}
|
||||
|
||||
if (target_arch == "x86") {
|
||||
lib_asm_flags += [
|
||||
"-f",
|
||||
"elf",
|
||||
]
|
||||
}
|
||||
|
||||
if (target_arch == "x86_64") {
|
||||
lib_asm_flags += [
|
||||
"-f",
|
||||
"elf64",
|
||||
]
|
||||
}
|
||||
|
||||
if (target_arch == "arm32") {
|
||||
lib_c_flags += [
|
||||
"-fno-builtin",
|
||||
"-march=armv7-a",
|
||||
"-mfpu=neon-vfpv4",
|
||||
"-mfloat-abi=softfp",
|
||||
"-fno-pie",
|
||||
]
|
||||
lib_asm_flags += [
|
||||
"-march=armv7-a",
|
||||
"-mfpu=neon-vfpv4",
|
||||
"-mfloat-abi=softfp",
|
||||
"-mcpu=cortex-a15",
|
||||
]
|
||||
}
|
||||
|
||||
if (target_arch == "arm64") {
|
||||
lib_c_flags += [
|
||||
"-fno-builtin",
|
||||
"-mcpu=cortex-a53+nocrypto+nocrc",
|
||||
"-fno-pie",
|
||||
]
|
||||
lib_asm_flags += [ "-mcpu=cortex-a53+nocrypto+nocrc" ]
|
||||
}
|
||||
|
||||
if (target_arch == "riscv64") {
|
||||
lib_c_flags += [
|
||||
"-fno-builtin",
|
||||
"-march=rv64ima",
|
||||
"-mabi=lp64",
|
||||
"-fno-pie",
|
||||
]
|
||||
lib_asm_flags += [
|
||||
"-march=rv64ima",
|
||||
"-mabi=lp64",
|
||||
]
|
||||
}
|
||||
|
||||
config("lib_flags") {
|
||||
cflags = lib_c_flags
|
||||
asmflags = lib_asm_flags
|
||||
}
|
||||
|
||||
config("libobjcc_flags") {
|
||||
cflags = lib_c_flags
|
||||
cflags_objcc = lib_objcc_flags
|
||||
cflags_cc = lib_cc_flags
|
||||
asmflags = lib_asm_flags
|
||||
}
|
||||
|
||||
config("libcxx_flags") {
|
||||
cflags = lib_c_flags
|
||||
asmflags = lib_asm_flags
|
||||
cflags_cc = lib_cc_flags
|
||||
}
|
||||
|
||||
group("libs") {
|
||||
deps = [
|
||||
"//libs/libc:libc",
|
||||
"//libs/libcxx:libcxx",
|
||||
"//libs/libfoundation:libfoundation",
|
||||
"//libs/libg:libg",
|
||||
"//libs/libui:libui",
|
||||
]
|
||||
|
||||
if (objc_support) {
|
||||
deps += [ "//libs/libobjc:libobjc" ]
|
||||
}
|
||||
}
|
||||
102
build/libs/TEMPLATE.gni
Normal file
102
build/libs/TEMPLATE.gni
Normal file
@@ -0,0 +1,102 @@
|
||||
template("xOS_static_library") {
|
||||
assert(defined(invoker.sources),
|
||||
"Need sources in $target_name to build static library")
|
||||
|
||||
lib_name = target_name
|
||||
lib_build_name = lib_name + "_build"
|
||||
lib_include_config_name = lib_name + "_include_config"
|
||||
compiled_lib_output_name_base = "$root_out_dir/tmp/libs/"
|
||||
compiled_lib_output_name = compiled_lib_output_name_base + lib_name
|
||||
final_lib_output_name = "$root_out_dir/base/libs/" + lib_name + ".a"
|
||||
building_deplib_bulders_list = []
|
||||
linking_deplib_bulders_list = []
|
||||
linking_deplib_list = []
|
||||
includes = []
|
||||
|
||||
if (defined(invoker.include_dirs)) {
|
||||
includes = invoker.include_dirs
|
||||
}
|
||||
|
||||
if (defined(invoker.deplibs)) {
|
||||
foreach(i, invoker.deplibs) {
|
||||
fullname = "//libs/" + i + ":" + i
|
||||
|
||||
# To speed up compilation we have separate deps for builing and linking stages.
|
||||
# The only library which is required to be a dependancy for building stage is libfreetype,
|
||||
# since its header files might not be available initially (they are archived).
|
||||
if (i == "libfreetype") {
|
||||
building_deplib_bulders_list += [ fullname + "_build" ]
|
||||
}
|
||||
|
||||
linking_deplib_bulders_list += [ fullname + "_build" ]
|
||||
linking_deplib_list += [ compiled_lib_output_name_base +
|
||||
get_label_info(fullname, "name") + ".a" ]
|
||||
includes += [ "//libs/" + i + "/include" ]
|
||||
|
||||
# Also adding libc includes.
|
||||
# Note to add libc after libcxx.
|
||||
if (i == "libcxx") {
|
||||
includes += [ "//libs/libc/include" ]
|
||||
}
|
||||
|
||||
# LibAPI is a lightweight library to use shared headers with API between libs and apps.
|
||||
if (i == "libui") {
|
||||
includes += [ "//libs/libapi/include" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
includes += [ "//libs/" + lib_name + "/include" ]
|
||||
|
||||
# The output library is passed at the end.
|
||||
linking_deplib_list += [ compiled_lib_output_name + ".a" ]
|
||||
linking_deplib_bulders_list += [ "//libs/" + lib_name + ":" + lib_build_name ]
|
||||
|
||||
# Use a strange __EMPTY_PATH_, empty string can't be passed as an arg.
|
||||
path_to_bins = "__EMPTY_PATH_"
|
||||
if (host == "llvm") {
|
||||
path_to_bins = llvm_bin_path
|
||||
}
|
||||
|
||||
script_args = [
|
||||
"$target_arch",
|
||||
"$host",
|
||||
"$path_to_bins",
|
||||
rebase_path("$final_lib_output_name", root_build_dir),
|
||||
]
|
||||
|
||||
foreach(i, linking_deplib_list) {
|
||||
script_args += [ rebase_path(i, root_build_dir) ]
|
||||
}
|
||||
|
||||
config(lib_include_config_name) {
|
||||
include_dirs = includes
|
||||
}
|
||||
|
||||
# Create a build rule to compile only a lib with unresolved references from other libs
|
||||
static_library(lib_build_name) {
|
||||
output_name = "tmp/libs/" + lib_name
|
||||
sources = invoker.sources
|
||||
include_dirs = includes
|
||||
deps = building_deplib_bulders_list
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"configs",
|
||||
"cflags",
|
||||
"cflags_c",
|
||||
"cflags_cc",
|
||||
"cflags_objc",
|
||||
"cflags_objcc",
|
||||
"asmflags",
|
||||
"deps",
|
||||
"public_deps",
|
||||
])
|
||||
}
|
||||
|
||||
action(lib_name) {
|
||||
script = "//build/libs/merge_libs.py"
|
||||
inputs = linking_deplib_list
|
||||
outputs = [ "$final_lib_output_name" ]
|
||||
deps = linking_deplib_bulders_list
|
||||
args = script_args
|
||||
}
|
||||
}
|
||||
83
build/libs/merge_libs.py
Normal file
83
build/libs/merge_libs.py
Normal file
@@ -0,0 +1,83 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import random
|
||||
AR_TOOL = ""
|
||||
|
||||
arch = sys.argv[1]
|
||||
host = sys.argv[2]
|
||||
path_to_bins = sys.argv[3]
|
||||
target_lib = sys.argv[4]
|
||||
srcs_lib = list(sys.argv[5:])
|
||||
|
||||
if path_to_bins == "__EMPTY_PATH_":
|
||||
path_to_bins = ""
|
||||
if len(path_to_bins) != 0:
|
||||
if path_to_bins[-1] != '/':
|
||||
path_to_bins += "/"
|
||||
|
||||
if (arch == "arm32"):
|
||||
if host == "gnu":
|
||||
AR_TOOL = "{0}arm-none-eabi-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"../toolchains/gcc_runtime/10.2.1/arm-none-eabi-libgcc.a")
|
||||
elif host == "llvm":
|
||||
AR_TOOL = "{0}llvm-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.builtins-arm.a")
|
||||
elif (arch == "x86"):
|
||||
if host == "gnu":
|
||||
AR_TOOL = "{0}i686-elf-ar".format(path_to_bins)
|
||||
elif host == "llvm":
|
||||
AR_TOOL = "{0}llvm-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"/usr/lib/llvm-18/lib/clang/18/lib/linux/libclang_rt.builtins-i386.a")
|
||||
elif (arch == "x86_64"):
|
||||
if host == "gnu":
|
||||
AR_TOOL = "{0}x86_64-elf-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"../toolchains/gcc_runtime/10.2.1/x86_64-libgcc.a")
|
||||
elif host == "llvm":
|
||||
AR_TOOL = "{0}llvm-ar".format(path_to_bins)
|
||||
elif (arch == "arm64"):
|
||||
if host == "gnu":
|
||||
AR_TOOL = "{0}aarch64-elf-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"../toolchains/gcc_runtime/10.2.1/aarch64-libgcc.a")
|
||||
elif host == "llvm":
|
||||
AR_TOOL = "{0}llvm-ar".format(path_to_bins)
|
||||
else:
|
||||
print("Unsupported host for arch {0}".format(host, arch))
|
||||
exit(1)
|
||||
elif (arch == "riscv64"):
|
||||
if host == "gnu":
|
||||
AR_TOOL = "{0}riscv64-unknown-elf-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"../toolchains/gcc_runtime/10.2.1/riscv64-libgcc.a")
|
||||
elif host == "llvm":
|
||||
AR_TOOL = "{0}llvm-ar".format(path_to_bins)
|
||||
srcs_lib.append(
|
||||
"../toolchains/gcc_runtime/10.2.1/riscv64-libgcc.a")
|
||||
else:
|
||||
print("Unsupported host for arch {0}".format(host, arch))
|
||||
exit(1)
|
||||
else:
|
||||
print("Unsupported arch {0}".format(arch))
|
||||
exit(1)
|
||||
|
||||
if (len(srcs_lib) == 1):
|
||||
output = subprocess.check_output(
|
||||
"cp {1} {0}".format(target_lib, srcs_lib[0]), shell=True)
|
||||
else:
|
||||
filename = "libmerger{0}.mri".format(random.randint(10000, 100000))
|
||||
|
||||
ffile = open(filename, "w")
|
||||
ffile.write("CREATE {0}\n".format(target_lib))
|
||||
for i in srcs_lib:
|
||||
ffile.write("ADDLIB {0}\n".format(i))
|
||||
ffile.write("SAVE\n")
|
||||
ffile.write("END")
|
||||
ffile.close()
|
||||
|
||||
output = subprocess.check_output(
|
||||
"{0} -M <{1}".format(AR_TOOL, filename), shell=True)
|
||||
output = subprocess.check_output("rm {0}".format(filename), shell=True)
|
||||
Reference in New Issue
Block a user