mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 20:36:31 +00:00
修改libc的编译相关内容(#171)
1.将libc的include文件夹分为export和internal 2.将所有app都直接链接libc.a,而不是都执行一遍"搜索.o"的过程
This commit is contained in:
45
user/libs/libc/build.rs
Normal file
45
user/libs/libc/build.rs
Normal file
@ -0,0 +1,45 @@
|
||||
extern crate bindgen;
|
||||
// use ::std::env;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Tell cargo to look for shared libraries in the specified directory
|
||||
println!("cargo:rustc-link-search=src");
|
||||
println!("cargo:rerun-if-changed=src/include/internal/bindings/wrapper.h");
|
||||
|
||||
// let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
let out_path = PathBuf::from(String::from("src/include/internal/bindings/"));
|
||||
|
||||
// The bindgen::Builder is the main entry point
|
||||
// to bindgen, and lets you build up options for
|
||||
// the resulting bindings.
|
||||
{
|
||||
let bindings = bindgen::Builder::default()
|
||||
.clang_arg("-I./src/include")
|
||||
.clang_arg("-I./src/include/export") // todo: 当引入多种架构之后,需要修改这里,对于不同的架构编译时,include不同的路径
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.header("src/include/internal/bindings/wrapper.h")
|
||||
.clang_arg("--target=x86_64-none-none")
|
||||
.clang_arg("-v")
|
||||
// 使用core,并将c语言的类型改为core::ffi,而不是使用std库。
|
||||
.use_core()
|
||||
.ctypes_prefix("::core::ffi")
|
||||
.generate_inline_functions(true)
|
||||
.raw_line("#![allow(dead_code)]")
|
||||
.raw_line("#![allow(non_upper_case_globals)]")
|
||||
.raw_line("#![allow(non_camel_case_types)]")
|
||||
// Tell cargo to invalidate the built crate whenever any of the
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
||||
}
|
@ -36,4 +36,4 @@ libc: $(libc_objs) $(libc_sub_dirs) libc_rust
|
||||
|
||||
libc_rust:
|
||||
rustup default nightly
|
||||
cargo +nightly build --release --target ./x86_64-unknown-none.json
|
||||
cargo +nightly build --release --target ./arch/x86_64/x86_64-unknown-none.json
|
1
user/libs/libc/src/include/internal/bindings/.gitignore
vendored
Normal file
1
user/libs/libc/src/include/internal/bindings/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
bindings.rs
|
1
user/libs/libc/src/include/internal/bindings/mod.rs
Normal file
1
user/libs/libc/src/include/internal/bindings/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod bindings;
|
15
user/libs/libc/src/include/internal/bindings/wrapper.h
Normal file
15
user/libs/libc/src/include/internal/bindings/wrapper.h
Normal file
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @file wrapper.h
|
||||
* @author longjin (longjin@RinGoTek.cn)
|
||||
* @brief 这是为libc的C代码的相关接口创建rust绑定的wrapper
|
||||
* @version 0.1
|
||||
* @date 2023-02-11
|
||||
*
|
||||
* @copyright Copyright (c) 2023
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// 这里导出在include/export文件夹下的头文件
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
1
user/libs/libc/src/include/internal/mod.rs
Normal file
1
user/libs/libc/src/include/internal/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod bindings;
|
1
user/libs/libc/src/include/mod.rs
Normal file
1
user/libs/libc/src/include/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod internal;
|
@ -7,9 +7,12 @@
|
||||
#[allow(non_upper_case_globals)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[allow(non_snake_case)]
|
||||
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
use include::internal::bindings::bindings::putchar;
|
||||
|
||||
mod include;
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
loop {}
|
||||
@ -17,5 +20,9 @@ fn panic(_info: &PanicInfo) -> ! {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn scanf() {
|
||||
|
||||
loop {
|
||||
unsafe {
|
||||
putchar(88);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user