Skip to main content

trivial_tests/
lib.rs

1// Copyright 2026 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#![no_std]
6
7// This crate has tests of the Rust build support and fundamental features of
8// the compiler and cross-language linkage support.  It is not a place to put
9// tests for other kernel code that happens to be in Rust.
10
11use test_macro::plus_one;
12
13#[unsafe(no_mangle)]
14pub static kConstVarDefinedInRust: i32 = 17;
15
16#[unsafe(no_mangle)]
17pub static mut gVarDefinedInRust: i32 = 42;
18
19unsafe extern "C" {
20    static kConstVarExportedToRust: i32;
21    static mut gVarExportedToRust: i32;
22} // extern "C"
23
24#[unsafe(no_mangle)]
25pub extern "C" fn add_one_in_rust(x: i32) -> i32 {
26    plus_one!(x)
27}
28
29#[unsafe(no_mangle)]
30pub extern "C" fn get_const_var_exported_to_rust() -> i32 {
31    unsafe { kConstVarExportedToRust }
32}
33
34#[unsafe(no_mangle)]
35pub extern "C" fn fetch_add_var_exported_to_rust(x: i32) -> i32 {
36    unsafe {
37        let old = gVarExportedToRust;
38        gVarExportedToRust += x;
39        old
40    }
41}