| # Copyright 2020 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. |
| |
| import("//build/components.gni") |
| import("//build/rust/rustc_library.gni") |
| import("//build/rust/rustc_wasm_library.gni") |
| |
| import("//src/diagnostics/wasm/wasm_bindings.gni") |
| |
| group("example") { |
| deps = [ |
| ":lib", |
| ":lib($unknown_wasm32_toolchain)", |
| ] |
| } |
| |
| group("tests") { |
| testonly = true |
| deps = [ |
| ":test_wasm_exists", |
| ":wasm-example-unittests", |
| ] |
| } |
| |
| # We need to specify configs |
| config("env") { |
| rustenv = [ |
| "CARGO_PKG_NAME=example_lib", |
| "CARGO_PKG_VERSION=0.1", |
| "CARGO_MANIFEST_DIR=/", |
| ] |
| } |
| |
| lib_sources = [ "src/lib.rs" ] |
| |
| if (current_toolchain == unknown_wasm32_toolchain) { |
| rustc_wasm_library("lib") { |
| output_name = "example_lib" |
| edition = "2021" |
| |
| configs += [ ":env" ] |
| |
| deps = [ "//third_party/rust_crates:wasm-bindgen" ] |
| |
| sources = lib_sources |
| } |
| } else { |
| rustc_library("lib") { |
| edition = "2021" |
| |
| configs += [ ":env" ] |
| |
| sources = lib_sources |
| } |
| } |
| |
| rustc_test("example_lib_tests") { |
| edition = "2021" |
| |
| sources = lib_sources |
| |
| deps = [ "//src/lib/fuchsia" ] |
| } |
| |
| fuchsia_unittest_package("wasm-example-unittests") { |
| deps = [ ":example_lib_tests" ] |
| } |
| |
| wasm_bindings("lib_wasm") { |
| target = ":lib" |
| target_output_name = "example_lib" |
| } |
| |
| copy("test_wasm_exists") { |
| dep_path = get_label_info(":lib($unknown_wasm32_toolchain)", "root_out_dir") |
| sources = [ "${dep_path}/libexample_lib.wasm" ] |
| outputs = [ "${root_out_dir}/test_wasm_exists_libexample_lib.wasm" ] |
| |
| deps = [ ":lib($unknown_wasm32_toolchain)" ] |
| } |