1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! bindgen test for hello world
17 #![allow(clippy::approx_constant)]
18 mod c_ffi {
19 #![allow(dead_code)]
20 #![allow(non_upper_case_globals)]
21 #![allow(non_camel_case_types)]
22 include!(env!("BINDGEN_RS_FILE"));
23 }
24 /// pub fn add_two_numbers_in_c
add_two_numbers_in_c(a: u32, b: u32) -> u3225 pub fn add_two_numbers_in_c(a: u32, b: u32) -> u32 {
26 unsafe { c_ffi::FuncAAddB(a, b) }
27 }
28
29 use std::ffi::c_char;
30 use std::ffi::CString;
31
32 /// fn main()
main()33 fn main() {
34 println!("{} + {} = {}", 3, 7, add_two_numbers_in_c(3, 7));
35 let c_str = CString::new("This is a message from C").unwrap();
36 let c_world: *const c_char = c_str.as_ptr() as *const c_char;
37 unsafe {
38 c_ffi::SayHello(c_world);
39 }
40 }
41