| # Copyright 2022 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( |
| "@rules_fuchsia//fuchsia:defs.bzl", |
| "fuchsia_component", |
| "fuchsia_component_manifest", |
| "fuchsia_package", |
| "fuchsia_test_component", |
| "fuchsia_test_package", |
| "fuchsia_wrap_rust_binary", |
| ) |
| load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test") |
| |
| rust_binary( |
| name = "hello_fuchsia_rust_native", |
| srcs = ["src/main.rs"], |
| edition = "2024", |
| rustc_flags = [ |
| "-Cpanic=abort", |
| ], |
| |
| # TODO(https://fxbug.dev/42065890) make this be included automatically for all rust binaries. |
| deps = [ |
| "//third_party/rust_crates/vendor:anyhow", |
| ] + select({ |
| "@platforms//os:fuchsia": ["@fuchsia_sdk//pkg/fdio"], |
| "//conditions:default": [], |
| }), |
| ) |
| |
| fuchsia_wrap_rust_binary( |
| name = "hello_fuchsia_rust_bin", |
| native_binary = ":hello_fuchsia_rust_native", |
| ) |
| |
| fuchsia_component_manifest( |
| name = "manifest", |
| src = "meta/hello_fuchsia_rust.cml", |
| ) |
| |
| fuchsia_component( |
| name = "component", |
| manifest = ":manifest", |
| deps = [":hello_fuchsia_rust_bin"], |
| ) |
| |
| fuchsia_package( |
| name = "pkg", |
| package_name = "hello_fuchsia_rust", |
| components = [":component"], |
| fuchsia_api_level = "HEAD", |
| visibility = ["//visibility:public"], |
| ) |
| |
| rust_test( |
| name = "hello_fuchsia_rust_test_native", |
| crate = ":hello_fuchsia_rust_native", |
| rustc_flags = [ |
| "-Zpanic_abort_tests", |
| "-Cpanic=abort", |
| ], |
| deps = [ |
| "//third_party/rust_crates/vendor:assert_matches", |
| "@fuchsia_sdk//pkg/fdio", |
| ], |
| ) |
| |
| fuchsia_wrap_rust_binary( |
| name = "hello_fuchsia_rust_test", |
| testonly = True, |
| native_binary = ":hello_fuchsia_rust_test_native", |
| ) |
| |
| fuchsia_component_manifest( |
| name = "test_manifest", |
| src = "meta/hello_fuchsia_rust_test.cml", |
| ) |
| |
| fuchsia_test_component( |
| name = "test_component", |
| manifest = ":test_manifest", |
| deps = [":hello_fuchsia_rust_test"], |
| ) |
| |
| fuchsia_test_package( |
| name = "test_pkg", |
| package_name = "hello_fuchsia_rust_test", |
| fuchsia_api_level = "HEAD", |
| test_components = [":test_component"], |
| visibility = ["//visibility:public"], |
| ) |
| |
| # TODO(https://fxbug.dev/42069350): fix and uncomment below. |
| #rust_doc( |
| # name = "hello_fuchsia_rust_doc", |
| # crate = ":hello_fuchsia_rust_native", |
| #) |
| |
| filegroup( |
| name = "hello_fuchsia_rust", |
| testonly = True, |
| srcs = [ |
| ":pkg", |
| ":test_pkg", |
| ], |
| visibility = ["//visibility:public"], |
| ) |