| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # IMPORTANT: This file serves to build the Fuchsia platform sysroot, used |
| # at build time to provide the C library, the Zircon VDSO, and a few linker |
| # stubs for legacy link targets like libm.so. Plus all associated headers. |
| |
| sysroot_toolchain = "//build/zircon:sysroot_toolchain" |
| sysroot_dir = get_label_info(":sysroot($sysroot_toolchain)", "root_out_dir") |
| sysroot_dir += "/sysroot" |
| |
| if (current_toolchain != sysroot_toolchain) { |
| # Depend on this to only require the Zircon headers, but not link to the |
| # C library or Zircon VDSO. |
| group("headers") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| |
| # Any regular Fuchsia binary should depend on this target to ensure the |
| # sysroot is properly setup, i.e. all headers are present and the C library, |
| # VDSO library and stub libraries are built. |
| group("cpp_binary_deps") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| |
| # An additional dependency for executable() Fuchsia user binaries. It adds |
| # the C runtime startup object code. |
| group("crt1_deps") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| |
| # Rust binaries should depend on this target only. |
| group("rust_binary_deps") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| |
| # Go binaries should depend on this targe tonly. |
| group("go_binary_deps") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| |
| # A special dependency that ensure that the uninstrumented C library is |
| # available in the system package as /lib/ld.so.1. For more details read |
| # //zircon/system/ulib/c/libc_toolchain.gni |
| # |
| # In practice, should only be used by the package() template, and some |
| # prebuilt driver binaries. |
| group("system_libc_deps") { |
| public_deps = [ ":$target_name($sysroot_toolchain)" ] |
| } |
| } else { |
| import("//build/config/fuchsia/zircon.gni") |
| import("//build/config/fuchsia/zircon_legacy_vars.gni") |
| |
| sysroot_dir = get_label_info(":sysroot($sysroot_toolchain)", "root_out_dir") |
| sysroot_dir += "/sysroot" |
| |
| # For historical reasons, only the scopes with an `sdk` key are considered |
| # here. Each value associated with an `sdk` key is a scope itself, with the |
| # following schema: |
| # |
| # If `include_dir` is present then: |
| # |
| # include_dir (optional) |
| # [GN path] A GN path to a subdirectory containing zero or more headers |
| # to copy to the sysroot's include directory. |
| # |
| # headers (optional) |
| # [list of paths] Required if `include_dir` is specified, ignored otherwise. |
| # A list of header sub-paths, relative to `include_dir`, that must be |
| # copied to the sysroot directory. |
| # |
| # no_export (optional) |
| # [boolean] Ignored if `include_dir` is not used. A flag that is set to |
| # indicate that the set of headers described in the current entry should |
| # not be exported to the SDK sysroot (though they will still be copied |
| # to the platform's sysroot). This is useful for <zircon/device/*.h> |
| # headers, as well as `testonly-cdecls.inc`. |
| # |
| # Otherwise, if `include_dir` is _not_ present: |
| # |
| # source (optional) |
| # [path] A path, relative to the current root build directory, where |
| # to find the source file to be copied into the sysroot, where destination |
| # is specified by one of the ` link`, `debug` or `dist` keys described |
| # below. Ignored if `include_dir` is present. |
| # |
| # debug (optional) |
| # dist (optional) |
| # link (optional) |
| # [path] A path relative to the sysroot directory, that specifies where |
| # the `source` file needs to be copied into the SDK. Only one of these |
| # keys can be used per entry. For the platform SDK, onle `dist` and `link` |
| # are used. The SDK sysroot will use all three though. |
| # |
| # deps (optional) |
| # [list of labels] A list of labels to dependencies for this entry, |
| # this should correspond to the GN target that built the `source` |
| # file, once the sysroot generation is moved to the Fuchsia build. |
| # |
| # IMPORTANT: The populate_sysroot_headers.py script in this directory relies |
| # on this exact schema definition. Keep it in sync if the schema changes! |
| # |
| sysroot_headers = [] |
| sysroot_headers_deps = [] |
| sysroot_deps = [] |
| i = 0 |
| foreach(entry, zircon_legacy_sysroot) { |
| if (defined(entry.sdk)) { |
| sdk = { |
| } |
| sdk = entry.sdk |
| if (defined(sdk.headers)) { |
| # This has to generate a separate copy() target for each file. |
| dir = rebase_path(sdk.include_dir, "", root_build_dir) |
| foreach(file, sdk.headers) { |
| sysroot_headers += [ "$sysroot_dir/include/$file" ] |
| if (defined(sdk.deps)) { |
| # Some dependencies are necessary for auto-generated headers. |
| # NOTE: This branch will never be taken when parsing zircon_legacy_sysroot |
| # but it will be once we switch to parsing the sysroot_entries directly. |
| # For now, hack the missing dependency in sysroot_headers below. |
| sysroot_headers_deps += sdk.deps |
| } |
| } |
| } else if (defined(sdk.link)) { |
| file = "$sysroot_dir/${sdk.link}" |
| |
| # Only copy link libraries to the sysroot, because copying |
| # distribution libraries will populate the build's metadata |
| # with unwanted installation entries for /lib/ld.so.1 (e.g. |
| # when using the "gcc" variant). |
| i = i + 1 |
| copy_target = "copy_$i" |
| sysroot_deps += [ ":$copy_target" ] |
| copy(copy_target) { |
| visibility = [ ":sysroot" ] |
| sources = [ "$zircon_root_build_dir/${sdk.source}" ] |
| outputs = [ file ] |
| forward_variables_from(sdk, [ "deps" ]) |
| } |
| } |
| } |
| } |
| |
| # Write sysroot_entries to a JSON file that will get parsed |
| # by our populate_sysroot_headers.py script below. |
| import("//zircon/system/ulib/c/sysroot_entries.gni") |
| import("//zircon/system/ulib/zircon/sysroot_entries.gni") |
| sysroot_entries_json_file = "$root_out_dir/sysroot-entries.json" |
| |
| generated_file("sysroot-entries-json") { |
| visibility = [ ":*" ] |
| outputs = [ sysroot_entries_json_file ] |
| contents = sysroot_uninstrumented_libc_entries + |
| sysroot_instrumented_libc_entries + sysroot_crt1_entries + |
| sysroot_vdso_entries |
| output_conversion = "json" |
| } |
| |
| action("headers") { |
| inputs = [ sysroot_entries_json_file ] |
| outputs = sysroot_headers |
| depfile = "$root_out_dir/sysroot_headers.d" |
| script = "populate_sysroot_headers.py" |
| args = [ |
| "--src-dir", |
| rebase_path("//", root_build_dir), |
| "--sysroot-json", |
| rebase_path(inputs[0], root_build_dir), |
| "--sysroot-dir", |
| rebase_path(sysroot_dir, root_build_dir), |
| "--dep-file", |
| rebase_path(depfile, root_build_dir), |
| |
| # The --debug flag can be used to print the script's operations for debugging. |
| #"--debug", |
| ] |
| deps = [ ":sysroot-entries-json" ] + sysroot_headers_deps |
| |
| # NOTE: This extra dependency is because the zircon_legacy_entries don't have |
| # the right dependencies on the Fuchsia build target that generates some |
| # Zircon headers. This can go away once we switch to parsing the sysroot_entries |
| # directly. See the comment about sdk.deps for headers above too. |
| deps += [ "//zircon/vdso:public($default_toolchain)" ] |
| |
| visibility = [ ":*" ] |
| } |
| |
| group("sysroot") { |
| deps = sysroot_deps + [ ":headers" ] |
| } |
| |
| # TODO(60613): Split sysroot into the proper dependencies. |
| group("cpp_binary_deps") { |
| deps = [ ":sysroot" ] |
| } |
| |
| group("crt1_deps") { |
| # Nothing for now |
| } |
| |
| group("rust_binary_deps") { |
| deps = [ ":sysroot" ] |
| } |
| |
| group("go_binary_deps") { |
| deps = [ ":sysroot" ] |
| } |
| |
| group("system_libc_deps") { |
| data_deps = [ system_libc_target ] |
| } |
| } |