diff --git a/.gitignore b/.gitignore index b88556e..abfeadc 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,5 @@ rust-project.json ext_images .idea -lwext4-sys/lwext4 \ No newline at end of file +lwext4-sys/lwext4 +lwext4-sys/src/ext4.rs \ No newline at end of file diff --git a/lwext4-rs/src/file.rs b/lwext4-rs/src/file.rs index b1df6a2..7d93f7e 100644 --- a/lwext4-rs/src/file.rs +++ b/lwext4-rs/src/file.rs @@ -1,8 +1,8 @@ use crate::block::CName; use crate::error::{errno_to_result, Error, Result}; use crate::types::{FileAttr, FileTimes, Metadata, OpenFlags, Permissions, Time}; -use alloc::string::ToString; use alloc::string::String; +use alloc::string::ToString; use core::ptr::null_mut; use embedded_io::{ErrorType, Read, Seek, SeekFrom, Write}; use lwext4_sys::ext4::*; diff --git a/lwext4-rs/src/mkfs.rs b/lwext4-rs/src/mkfs.rs index d52ac46..5224d9f 100644 --- a/lwext4-rs/src/mkfs.rs +++ b/lwext4-rs/src/mkfs.rs @@ -1,15 +1,15 @@ +use crate::alloc::string::ToString; use crate::error::{errno_to_result, Result}; use crate::types::FsType; use crate::{BlockDevice, BlockDeviceInterface, Error}; use alloc::boxed::Box; use alloc::ffi::CString; +use alloc::string::String; use core::ffi::CStr; use core::fmt::Debug; use core::mem::transmute; use core::pin::Pin; use core::ptr::null_mut; -use crate::alloc::string::ToString; -use alloc::string::String; use lwext4_sys::ext4::{ext4_fs, ext4_mkfs, ext4_mkfs_info, ext4_mkfs_read_info, ext4_sblock}; pub struct BuildExtFs { raw_fs: ext4_fs, diff --git a/lwext4-rs/src/types.rs b/lwext4-rs/src/types.rs index 6544dbf..721d8bb 100644 --- a/lwext4-rs/src/types.rs +++ b/lwext4-rs/src/types.rs @@ -4,13 +4,13 @@ use core::fmt::{Debug, Formatter}; use core::ops::{Deref, DerefMut}; use lwext4_sys::ext4::*; -pub const S_IFIFO:u32 = 4096; -pub const S_IFCHR:u32 = 8192; -pub const S_IFBLK:u32 = 24576; -pub const S_IFDIR:u32 = 16384; -pub const S_IFREG:u32 = 32768; -pub const S_IFLNK:u32 = 40960; -pub const S_IFSOCK:u32 = 49152; +pub const S_IFIFO: u32 = 4096; +pub const S_IFCHR: u32 = 8192; +pub const S_IFBLK: u32 = 24576; +pub const S_IFDIR: u32 = 16384; +pub const S_IFREG: u32 = 32768; +pub const S_IFLNK: u32 = 40960; +pub const S_IFSOCK: u32 = 49152; bitflags! { pub struct DebugFlags: u32 { const BALLOC = DEBUG_BALLOC; diff --git a/lwext4-sys/.gitignore b/lwext4-sys/.gitignore deleted file mode 100644 index 6956355..0000000 --- a/lwext4-sys/.gitignore +++ /dev/null @@ -1 +0,0 @@ -./src/ext4.rs \ No newline at end of file diff --git a/lwext4-sys/build.rs b/lwext4-sys/build.rs index b89748d..dc58718 100644 --- a/lwext4-sys/build.rs +++ b/lwext4-sys/build.rs @@ -1,11 +1,11 @@ -use std::{env, fs}; use std::path::PathBuf; use std::process::Command; +use std::{env, fs}; fn main() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let lwext4 = out_dir.join("lwext4"); - if !lwext4.exists(){ + if !lwext4.exists() { fs::create_dir_all(lwext4.clone()).unwrap(); let cp = Command::new("git") .current_dir(out_dir.clone()) @@ -14,22 +14,25 @@ fn main() { .arg("lwext4") .status() .expect("failed to clone lwext4"); - assert_eq!(cp.success(),true); + assert_eq!(cp.success(), true); } let os = env::var("CARGO_CFG_TARGET_OS").unwrap(); - if os == "none"{ + if os == "none" { build_for_none(&lwext4); - }else { + } else { build_for_os(&lwext4); } println!("cargo:rustc-link-lib=static=lwext4"); - println!("cargo:rerun-if-changed={}",PathBuf::from("ext4.h").canonicalize().unwrap().display()); + println!( + "cargo:rerun-if-changed={}", + PathBuf::from("ext4.h").canonicalize().unwrap().display() + ); } -fn build(lwext4:&PathBuf,lwext4_build:&PathBuf,build_arg:&str){ +fn build(lwext4: &PathBuf, lwext4_build: &PathBuf, build_arg: &[&str]) { let make = Command::new("make") .current_dir(&lwext4) - .arg(build_arg) + .args(build_arg) .status() .expect("failed to build lwext4"); assert!(make.success()); @@ -41,41 +44,50 @@ fn build(lwext4:&PathBuf,lwext4_build:&PathBuf,build_arg:&str){ assert!(make.success()); } -fn build_for_os(lwext4:&PathBuf){ +fn build_for_os(lwext4: &PathBuf) { let lwext4_build = lwext4.join("build_generic"); let lib_path = lwext4.join("build_generic/src/liblwext4.a"); - if !lwext4_build.exists() || !lib_path.exists(){ - build(lwext4,&lwext4_build,"generic"); - generates_bindings(&lwext4,"build_generic"); + if !lwext4_build.exists() || !lib_path.exists() { + build(lwext4, &lwext4_build, &["generic"]); + generates_bindings(&lwext4, "build_generic"); } - println!("cargo:rustc-link-search=native={}",lwext4_build.join("src").canonicalize().unwrap().display()); + println!( + "cargo:rustc-link-search=native={}", + lwext4_build.join("src").canonicalize().unwrap().display() + ); } - /// When the target is riscv64gc-unknown-none-elf, /// bindgen cannot correctly generate the c binding. /// We temporarily switch the target to the default x86_64-unknow-linux-gnu, /// and switch to the old value after completing the generation. -fn build_for_none(lwext4:&PathBuf){ +fn build_for_none(lwext4: &PathBuf) { let arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); - let lwext4_build = lwext4.join(format!("build_musl-generic-{}",arch)); - let lib_path = lwext4.join(format!("build_musl-generic-{}/src/liblwext4.a",arch)); - if !lwext4_build.exists() || !lib_path.exists(){ - build(lwext4,&lwext4_build,format!("musl-generic-{}",arch).as_str()); + println!("cargo:XXX={}", arch); + let lwext4_build = lwext4.join("build_musl-generic"); + let lib_path = lwext4.join("build_musl-generic/src/liblwext4.a"); + if !lwext4_build.exists() || !lib_path.exists() { + build( + lwext4, + &lwext4_build, + &["musl-generic", format!("ARCH={}", arch).as_str()], + ); let target = env::var("TARGET").unwrap(); - env::set_var("TARGET","x86_64-unknown-linux-gnu"); - generates_bindings(&lwext4,format!("build_musl-generic-{}",arch).as_str()); - env::set_var("TARGET",target); + env::set_var("TARGET", "x86_64-unknown-linux-gnu"); + generates_bindings(&lwext4, "build_musl-generic"); + env::set_var("TARGET", target); } - println!("cargo:rustc-link-search=native={}",lwext4_build.join("src").canonicalize().unwrap().display()); + println!( + "cargo:rustc-link-search=native={}", + lwext4_build.join("src").canonicalize().unwrap().display() + ); } - -fn generates_bindings(lwext4: &PathBuf, build_dir:&str) { +fn generates_bindings(lwext4: &PathBuf, build_dir: &str) { let bindings = bindgen::builder() .header("./ext4.h") - .clang_arg(format!("-I{}/include",lwext4.display())) - .clang_arg(format!("-I{}/{}/include",lwext4.display(),build_dir)) + .clang_arg(format!("-I{}/include", lwext4.display())) + .clang_arg(format!("-I{}/{}/include", lwext4.display(), build_dir)) .use_core() .layout_tests(false) .parse_callbacks(Box::new(bindgen::CargoCallbacks)) @@ -83,4 +95,3 @@ fn generates_bindings(lwext4: &PathBuf, build_dir:&str) { .unwrap(); bindings.write_to_file("src/ext4.rs").unwrap(); } -