| # Copyright 2026 The Fuchsia Authors |
| # |
| # Use of this source code is governed by a MIT-style |
| # license that can be found in the LICENSE file or at |
| # https://opensource.org/licenses/MIT |
| |
| import("//build/config/zircon/standard.gni") |
| import("//build/toolchain/zircon/zircon_toolchain_suite.gni") |
| import("//zircon/kernel/params.gni") |
| |
| # A kernel "switchset" is a suite of kernel-specific GN toolchains parameterized |
| # by target architecture. A switchset represents a set of kernel-defining |
| # compiler and linker flags. |
| # |
| # # Parameters |
| # |
| # TODO(https://fxbug.dev/371568912): Nothing to parameterize just yet. |
| template("kernel_switchset") { |
| assert( |
| current_toolchain == default_toolchain, |
| "A switchset should only be defined in the default toolchain (and not $current_toolchain)") |
| |
| # TODO(https://fxbug.dev/371568912): Remove once there are parameters |
| not_needed(invoker, "*") |
| |
| foreach(cpu, standard_fuchsia_cpus) { |
| zircon_toolchain_suite("${target_name}_$cpu") { |
| cpu = cpu |
| os = "fuchsia" |
| environment = "kernel" |
| |
| if (cpu == "x64") { |
| kernel_cpu = "x86" |
| } else { |
| kernel_cpu = cpu |
| } |
| |
| toolchain_tags = [ |
| "kernel", |
| "custom-abi", |
| "no-floating-point", |
| "standalone", |
| ] |
| |
| prefix_configs = [ |
| "//zircon/kernel:headers", |
| |
| # TODO(https://fxbug.dev/42121444): Many include/ headers use <ktl/*.h> headers. |
| "//zircon/kernel/lib/ktl:headers.config", |
| "//sdk/lib/fit:headers.config", |
| |
| # <arch/aspace.h> has #include <lib/mmu_rcu/simple_generational_rcu.h>. |
| "//zircon/kernel/lib/mmu_rcu:headers.config", |
| |
| # <stdlib.h> has #include <lib/heap.h>. |
| "//zircon/kernel/lib/heap:headers.config", |
| |
| # <lib/lockup_detector.h> is included by some "low-level" headers. |
| "//zircon/kernel/lib/lockup_detector:headers.config", |
| |
| # <kernel/percpu.h> has #include <lib/lazy_init/lazy_init.h>. |
| "//zircon/system/ulib/lazy_init:headers.config", |
| |
| # <kernel/spinlock.h> has #include <lockdep/lock_policy.h>. |
| "//zircon/system/ulib/lockdep:headers.config", |
| |
| # <kernel/{scheduler.h,scheduler_state.h> has #include <ffl/fixed.h>. |
| "//zircon/system/ulib/ffl:headers.config", |
| |
| # <kernel/thread.h> has #include <lib/kconcurrent/*.h>. |
| "//zircon/kernel/lib/kconcurrent:headers.config", |
| "//zircon/system/ulib/concurrent:headers.config", |
| |
| # <kernel/thread.h> has #include <vm/kstack.h>. |
| "//zircon/kernel/vm:headers.config", |
| |
| # <vm/page.h> has #include <vm/phys/arena.h> |
| "//zircon/kernel/vm/phys:headers.config", |
| |
| # <vm/vm_object.h> has #include <lib/user_copy/user_ptr.h>. |
| "//zircon/kernel/lib/user_copy:headers.config", |
| |
| # <vm/pmm_checker.h> has #include <lib/boot-options/boot-options.h>. |
| "//zircon/kernel/lib/acpi_lite:headers.config", |
| "//zircon/kernel/lib/boot-options:headers.config", |
| "//zircon/kernel/lib/devicetree:headers.config", |
| "//zircon/system/ulib/uart:headers.config", |
| "//zircon/system/ulib/hwreg:headers.config", |
| |
| # <vm/phys/arena.h> has #include <lib/memalloc/range.h> |
| "//zircon/kernel/phys/lib/memalloc:range.headers.config", |
| |
| # <lib/ktrace.h> has #include <lib/zircon-internal/ktrace.h>. |
| "//zircon/system/ulib/zircon-internal:headers.config", |
| |
| # <lib/ktrace.h> has #include <lib/spsc_buffer/spsc_buffer.h>. |
| "//zircon/kernel/lib/spsc_buffer:headers.config", |
| |
| # <lib/ktrace.h> has #include <lib/fxt/*.h>. |
| "//src/performance/lib/fxt:headers.config", |
| |
| # <lib/ktrace.h> has #include <lib/percpu_writer/percpu_buffer.h>. |
| "//zircon/kernel/lib/percpu_writer:headers.config", |
| |
| # <lib/fxt/section_symbols.h> has #include <lib/special-sections/special-sections.h>. |
| "//zircon/kernel/lib/special-sections:headers.config", |
| |
| # <kernel/thread.h> has #include <fbl/macros.h> |
| "//zircon/system/ulib/fbl:headers.config", |
| |
| # <dev/iommu.h> has #include <fbl/name.h> |
| "//zircon/kernel/lib/fbl:headers.config", |
| |
| # <reg.h> has #include <lib/mmio-ptr/mmio-ptr.h>. |
| "//zircon/system/ulib/mmio-ptr:headers.config", |
| |
| # <arch/*/hypervisor.h> has #include <lib/id_allocator.h>. |
| "//zircon/kernel/lib/id_allocator:headers.config", |
| |
| # Everywhere has #include <lib/fit/result.h> |
| # Everywhere has #include <lib/zx/result.h> |
| "//zircon/system/ulib/zx:headers.config", |
| |
| # Those (and others, like fbl) lead to stdcompat. |
| "//sdk/lib/stdcompat:headers.config", |
| |
| "//zircon/kernel/lib/backtrace:headers.config", |
| |
| "//zircon/kernel/lib/version:headers.config", |
| |
| "//zircon/kernel/lib/wake-vector:headers.config", |
| |
| "//zircon/kernel/lib/sched:headers.config", |
| |
| # <platform.h> has #include <lib/arch/ticks.h>. |
| "//zircon/kernel/lib/arch/$kernel_cpu:headers.config", |
| "//zircon/kernel/lib/arch:common-headers.config", |
| |
| # Many headers have #include <lib/zbi-format/zbi.h>. |
| "//sdk/lib/zbi-format:include", |
| |
| # <kernel/scheduler.h> depends on <lib/power-management/power-state.h> |
| "//zircon/kernel/lib/power-management:headers.config", |
| |
| # <kernel/scheduler.h> depends on <lib/stall.h> |
| "//zircon/kernel/lib/stall:headers.config", |
| |
| # <kernel/thread.h> depends on <lib/page-map/accessor.h> |
| "//zircon/kernel/lib/page-map:headers.config", |
| ] |
| |
| configs = [ "//zircon/kernel:kernel_config" ] |
| |
| # NOTE: kernel artifacts currently do not build under fuzzer |
| # variants. This was also true with the Zircon build, but |
| # the Fuchsia build never invoked it with corresponding |
| # variant selectors. Using an exclude_variant_tag is |
| # enough to fix the issue. |
| exclude_variant_tags = [ "fuzzer" ] |
| if (cpu == "riscv64") { |
| # TODO(https://fxbug.dev/42076027): no asan for riscv64 yet |
| exclude_variant_tags += [ "asan" ] |
| } else if (cpu == "arm64") { |
| # TODO(https://fxbug.dev/379891035): arm64 KASan support was |
| # temporarily removed and is to be reimplemeted. |
| exclude_variant_tags += [ "asan" ] |
| } |
| |
| # Always enable frame pointers in the kernel so there are panic |
| # backtraces and such. |
| # TODO(mcgrathr): Consider either removing this so there's a |
| # no-frame-pointers option, or removing the kernel's support for |
| # !WITH_FRAME_POINTERS if it will never be used. |
| remove_common_configs = [ "//build/config:default_frame_pointers" ] |
| configs += [ "//build/config:frame_pointers" ] |
| |
| if (cpu == "x64") { |
| # TODO(https://fxbug.dev/42101838): x86 kernel can't be built without --gc-sections |
| # because of crufty acpica code, and some compiler instrumentation |
| # is broken wrt --gc-sections semantics. |
| # Ensure that linker GC is enabled. |
| configs += [ "//build/config:linker_gc" ] |
| } |
| |
| # As a special case, kernel assertions are controlled by the kernel_debug_level |
| # variable, and not zx_assert_level (though it defaults to the same value, but |
| # some product configurations may decide to change it). |
| remove_common_configs += [ "//build/config/zircon:default_assert_level" ] |
| |
| # Map kernel_debug_level above 2 to an assert_level of 2, as that is the |
| # highest valid assertion level. |
| if (kernel_debug_level > 2) { |
| kernel_assert_level = 2 |
| } else { |
| kernel_assert_level = kernel_debug_level |
| } |
| configs += [ "//build/config/zircon:assert_level_$kernel_assert_level" ] |
| |
| # TODO(https://fxbug.dev/42150661): the kernel crashes on boot if built with -O0. |
| _optimize_none = [ "//build/config:optimize_none" ] |
| if (configs + _optimize_none - _optimize_none != configs) { |
| configs -= _optimize_none |
| configs += [ "//build/config:optimize_debug" ] |
| } |
| } |
| } |
| } |