sparrow-kata-full/apps/rust/hello/hello.rs
Sam Leffler b2117c9439 kata: rename kata-sdk-interface to sdk-interface
Rename the cate and functions to better identify things as
application-specific.

Change-Id: Ie4c888f6b0c0b66c2d4cfb6e0fb3b5b1e0b82c48
GitOrigin-RevId: 5ea9e1204023f717bbb63dcc0cf0579c1359e2da
2022-10-06 19:04:47 +00:00

38 lines
972 B
Rust

/*
* Copyright 2021, Google LLC
*
* SPDX-License-Identifier: Apache-2.0
*/
#![no_std]
#![no_main]
extern crate libkata;
use kata_os_common::logger::KataLogger;
use log::info;
use sdk_interface::*;
// Message output is sent through the kata-os-logger which calls logger_log
// to deliver data to the console. Redict to the sdk.
#[no_mangle]
#[allow(unused_variables)]
pub fn logger_log(_level: u8, msg: *const cstr_core::c_char) {
if let Ok(str) = unsafe { cstr_core::CStr::from_ptr(msg) }.to_str() {
let _ = sdk_log(str);
}
}
#[no_mangle]
pub fn main() {
// Setup logger; (XXX maybe belongs in the SDKRuntime)
static KATA_LOGGER: KataLogger = KataLogger;
log::set_logger(&KATA_LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Trace);
match sdk_ping() {
Ok(_) => info!("ping!"),
Err(e) => info!("sdk_ping failed: {:?}", e),
}
info!("I am a Rust app, hear me log!");
info!("Done, wimper ...");
}