| # Copyright 2026 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. | |
| load("@fuchsia_rules_common//build_flags:build_flags.bzl", "build_flags") | |
| load( | |
| "//build/bazel/rules/components:fx_component.bzl", | |
| "fx_component_manifest", | |
| "fx_test_component", | |
| ) | |
| load("//build/bazel/rules/packages:fx_package.bzl", "fx_package") | |
| load( | |
| "//build/bazel/rules/packages:fx_packaged_binary.bzl", | |
| "fx_packaged_binary", | |
| ) | |
| load("//build/bazel/rules/rust:rustc_binary.bzl", "rustc_binary") | |
| load("//build/bazel/rules/rust:rustc_test.bzl", "rustc_test") | |
| load("//build/bazel/rules/testing:fx_test.bzl", "fx_test") | |
| package(default_applicable_licenses = ["//:license"]) | |
| test_suite( | |
| name = "tests", | |
| tests = [":zxsh_tests"], | |
| visibility = ["//src/developer:__pkg__"], | |
| ) | |
| # LINT.IfChange(optimize-for-size) | |
| # build_flags() definitions are hand-ported rather than synced by bazel2gn. | |
| # @bazel2gn:skip | |
| build_flags( | |
| name = "optimize-for-size", | |
| # "opt-level=z" saves ~34 KiB on the zxsh binary in release builds. | |
| rustflags = ["-Copt-level=z"], | |
| ) | |
| # LINT.ThenChange(BUILD.gn:optimize-for-size) | |
| rustc_binary( | |
| name = "bin", | |
| srcs = [ | |
| "src/args.rs", | |
| "src/builtins/dump.rs", | |
| "src/builtins/echo.rs", | |
| "src/builtins/essential.rs", | |
| "src/builtins/file_utils.rs", | |
| "src/builtins/fuchsia.rs", | |
| "src/builtins/list.rs", | |
| "src/builtins/mod.rs", | |
| "src/builtins/msleep.rs", | |
| "src/builtins/printf.rs", | |
| "src/builtins/test.rs", | |
| "src/builtins/times.rs", | |
| "src/collections.rs", | |
| "src/errors.rs", | |
| "src/eval/arithmetic.rs", | |
| "src/eval/control_flow.rs", | |
| "src/eval/execution_context.rs", | |
| "src/eval/expand.rs", | |
| "src/eval/format.rs", | |
| "src/eval/glob.rs", | |
| "src/eval/mod.rs", | |
| "src/eval/redirect.rs", | |
| "src/eval/signals.rs", | |
| "src/eval/simple.rs", | |
| "src/eval/spawn.rs", | |
| "src/eval/state.rs", | |
| "src/fd.rs", | |
| "src/main.rs", | |
| "src/parser/ast.rs", | |
| "src/parser/error.rs", | |
| "src/parser/mod.rs", | |
| "src/parser/parser.rs", | |
| "src/parser/token.rs", | |
| "src/parser/tokenizer.rs", | |
| "src/path.rs", | |
| "src/process.rs", | |
| "src/relative.rs", | |
| "src/repl/completion.rs", | |
| "src/repl/mod.rs", | |
| "src/runner.rs", | |
| "src/serialization.rs", | |
| "src/sort.rs", | |
| "src/string.rs", | |
| "src/subshell.rs", | |
| "src/tests/args.rs", | |
| "src/tests/arithmetic.rs", | |
| "src/tests/ast.rs", | |
| "src/tests/builtins/dump.rs", | |
| "src/tests/builtins/echo.rs", | |
| "src/tests/builtins/essential.rs", | |
| "src/tests/builtins/file_utils.rs", | |
| "src/tests/builtins/fuchsia.rs", | |
| "src/tests/builtins/list.rs", | |
| "src/tests/builtins/mod.rs", | |
| "src/tests/builtins/msleep.rs", | |
| "src/tests/builtins/printf.rs", | |
| "src/tests/builtins/test.rs", | |
| "src/tests/builtins/times.rs", | |
| "src/tests/collections.rs", | |
| "src/tests/control_flow.rs", | |
| "src/tests/errors.rs", | |
| "src/tests/expand.rs", | |
| "src/tests/format.rs", | |
| "src/tests/glob.rs", | |
| "src/tests/mod.rs", | |
| "src/tests/parser.rs", | |
| "src/tests/path.rs", | |
| "src/tests/process.rs", | |
| "src/tests/redirect.rs", | |
| "src/tests/serialization.rs", | |
| "src/tests/signals.rs", | |
| "src/tests/simple.rs", | |
| "src/tests/sort.rs", | |
| "src/tests/spawn.rs", | |
| "src/tests/state.rs", | |
| "src/tests/string.rs", | |
| "src/tests/tokenizer.rs", | |
| "src/tty.rs", | |
| ], | |
| # We optimize zxsh for size because the binary is stored in bootfs and pinned | |
| # in memory all the time. | |
| build_flags = [":optimize-for-size"], | |
| crate_name = "zxsh", | |
| edition = "2024", | |
| visibility = ["//src/bringup/bin/netsvc:__pkg__"], | |
| deps = [ | |
| "//sdk/fidl/fuchsia.hardware.power.statecontrol:fuchsia.hardware.power.statecontrol_rust", | |
| "//sdk/fidl/fuchsia.hardware.pty:fuchsia.hardware.pty_rust", | |
| "//sdk/fidl/fuchsia.kernel:fuchsia.kernel_rust", | |
| "//sdk/rust/zx", | |
| "//src/lib/fdio/rust:fdio", | |
| "//src/lib/fuchsia-component", | |
| "//src/lib/fuchsia-runtime", | |
| "//src/lib/line-editor", | |
| "//third_party/rust_crates/vendor:bitflags", | |
| "//third_party/rust_crates/vendor:bstr", | |
| "//third_party/rust_crates/vendor:libc", | |
| "//third_party/rust_crates/vendor:zerocopy", | |
| ], | |
| ) | |
| fx_packaged_binary( | |
| name = "sh", | |
| binary = ":bin", | |
| binary_name = "sh", | |
| visibility = [ | |
| "//src/developer/console/test:__pkg__", | |
| "//src/lib/process:__pkg__", | |
| "//src/sys/tools/debug-dash-launcher/integration_test:__pkg__", | |
| ], | |
| ) | |
| rustc_test( | |
| name = "zxsh_bin_test", | |
| build_flags = [":optimize-for-size"], | |
| crate = ":bin", | |
| tags = ["manual"], | |
| target_compatible_with = ["@platforms//os:fuchsia"], | |
| visibility = ["//visibility:private"], | |
| ) | |
| fx_packaged_binary( | |
| name = "zxsh_packaged_bin", | |
| testonly = True, | |
| binary = ":bin", | |
| binary_name = "zxsh", | |
| ) | |
| fx_packaged_binary( | |
| name = "bin_test_packaged_bin", | |
| testonly = True, | |
| binary = ":zxsh_bin_test", | |
| binary_name = "zxsh_bin_test", | |
| ) | |
| fx_component_manifest( | |
| name = "zxsh_tests_manifest", | |
| testonly = True, | |
| component_name = "zxsh_tests", | |
| includes = [ | |
| "//sdk/lib/syslog:client.shard", | |
| "//src/sys/test_runners:tmp_storage.shard.cml", | |
| "//src/sys/test_runners/rust:default.shard.cml", | |
| ], | |
| manifest = "meta/zxsh_tests.cml", | |
| ) | |
| fx_test_component( | |
| name = "zxsh_tests_component", | |
| compiled_manifest = ":zxsh_tests_manifest", | |
| deps = [ | |
| ":bin_test_packaged_bin", | |
| ":zxsh_packaged_bin", | |
| ], | |
| ) | |
| fx_package( | |
| name = "zxsh_tests_package", | |
| package_name = "zxsh_tests", | |
| test_components = [":zxsh_tests_component"], | |
| ) | |
| fx_test( | |
| name = "zxsh_tests", | |
| package = ":zxsh_tests_package", | |
| ) |