Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 519e6aa

Browse files
alexreaperhulk
authored andcommitted
Start moving to 2018-style macros (#94)
* Start moving to 2018-style macros * Ooops, fix this too * More updates * Fix println import * Get rid of extern crates * Add this back * Fixes? * Better * Again? * Unused * magic * Try this? * Revert "Try this?" This reverts commit f89ec1b. * hygeinize * Mark the edition * FIxed hello-world * Better style * fmt * fmt; broken for the moment
1 parent 459e63f commit 519e6aa

File tree

13 files changed

+20
-36
lines changed

13 files changed

+20
-36
lines changed

build.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
extern crate bindgen;
2-
extern crate cc;
3-
extern crate shlex;
1+
use bindgen;
2+
use cc;
3+
use shlex;
44

55
use std::env;
66
use std::path::PathBuf;

hello-world/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#![no_std]
22
#![feature(alloc, const_str_as_bytes)]
33

4-
extern crate alloc;
54
use alloc::borrow::ToOwned;
65
use alloc::string::String;
76

8-
#[macro_use]
9-
extern crate linux_kernel_module;
7+
use linux_kernel_module;
8+
use linux_kernel_module::println;
109

1110
struct HelloWorldModule {
1211
message: String,
@@ -28,7 +27,7 @@ impl Drop for HelloWorldModule {
2827
}
2928
}
3029

31-
kernel_module!(
30+
linux_kernel_module::kernel_module!(
3231
HelloWorldModule,
3332
author: "Alex Gaynor and Geoffrey Thomas",
3433
description: "An extremely simple kernel module",

src/filesystem.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use core::default::Default;
33
use core::marker;
44
use core::mem;
55

6+
use bitflags;
7+
68
use crate::bindings;
79
use crate::c_types;
810
use crate::error;
@@ -24,7 +26,7 @@ pub trait FileSystem {
2426
const FLAGS: FileSystemFlags;
2527
}
2628

27-
bitflags! {
29+
bitflags::bitflags! {
2830
pub struct FileSystemFlags: c_types::c_int {
2931
const FS_REQUIRES_DEV = bindings::FS_REQUIRES_DEV as c_types::c_int;
3032
const FS_BINARY_MOUNTDATA = bindings::FS_BINARY_MOUNTDATA as c_types::c_int;
@@ -34,12 +36,6 @@ bitflags! {
3436
}
3537
}
3638

37-
impl FileSystemFlags {
38-
pub const fn const_empty() -> FileSystemFlags {
39-
FileSystemFlags { bits: 0 }
40-
}
41-
}
42-
4339
extern "C" fn fill_super_callback<T: FileSystem>(
4440
_sb: *mut bindings::super_block,
4541
_data: *mut c_types::c_void,

src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#![no_std]
2-
#![feature(allocator_api, const_fn, alloc_error_handler)]
2+
#![feature(allocator_api, alloc_error_handler)]
33

4-
#[macro_use]
54
extern crate alloc;
6-
#[macro_use]
7-
extern crate bitflags;
85

96
use core::panic::PanicInfo;
107

@@ -14,7 +11,6 @@ mod c_types;
1411
pub mod chrdev;
1512
mod error;
1613
pub mod filesystem;
17-
#[macro_use]
1814
pub mod printk;
1915
pub mod sysctl;
2016
mod types;
@@ -53,7 +49,7 @@ macro_rules! kernel_module {
5349
}
5450

5551
$(
56-
kernel_module!(@attribute $name, $value);
52+
$crate::kernel_module!(@attribute $name, $value);
5753
)*
5854
};
5955

src/sysctl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use alloc::boxed::Box;
2+
use alloc::vec;
23
use core::mem;
34
use core::ptr;
45
use core::sync::atomic;

src/user_ptr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use alloc::vec;
12
use alloc::vec::Vec;
23
use core::u32;
34

tests/chrdev/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![no_std]
22
#![feature(const_str_as_bytes)]
33

4-
#[macro_use]
5-
extern crate linux_kernel_module;
4+
use linux_kernel_module;
65

76
struct ChrdevTestModule {
87
_dev: linux_kernel_module::chrdev::DeviceNumberRegion,
@@ -19,7 +18,7 @@ impl linux_kernel_module::KernelModule for ChrdevTestModule {
1918
}
2019
}
2120

22-
kernel_module!(
21+
linux_kernel_module::kernel_module!(
2322
ChrdevTestModule,
2423
author: "Alex Gaynor and Geoffrey Thomas",
2524
description: "A module for testing character devices",

tests/chrdev/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate kernel_module_tests;
2-
31
use kernel_module_tests::with_kernel_module;
42
use std::fs;
53

tests/printk/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#![no_std]
22
#![feature(const_str_as_bytes)]
33

4-
#[macro_use]
5-
extern crate linux_kernel_module;
4+
use linux_kernel_module::{self, println};
65

76
struct PrintkTestModule;
87

@@ -16,7 +15,7 @@ impl linux_kernel_module::KernelModule for PrintkTestModule {
1615
}
1716
}
1817

19-
kernel_module!(
18+
linux_kernel_module::kernel_module!(
2019
PrintkTestModule,
2120
author: "Alex Gaynor and Geoffrey Thomas",
2221
description: "A module for testing println!()",

tests/printk/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate kernel_module_tests;
2-
31
use std::process::Command;
42

53
use kernel_module_tests::with_kernel_module;

tests/run_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def main():
5959
"rustc",
6060
"--test",
6161
"-Dwarnings",
62+
"--edition", "2018",
6263
"--out-dir", os.path.join(BASE_DIR, path),
6364
os.path.join(BASE_DIR, path, "tests.rs"),
6465
"--extern", "kernel_module_tests=libtestlib.rlib",
@@ -76,4 +77,3 @@ def main():
7677

7778
if __name__ == "__main__":
7879
main()
79-

tests/sysctl/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
use core::sync::atomic::AtomicBool;
55

6-
#[macro_use]
7-
extern crate linux_kernel_module;
6+
use linux_kernel_module;
87

98
use linux_kernel_module::sysctl::Sysctl;
109
use linux_kernel_module::Mode;
@@ -33,7 +32,7 @@ impl linux_kernel_module::KernelModule for SysctlTestModule {
3332
}
3433
}
3534

36-
kernel_module!(
35+
linux_kernel_module::kernel_module!(
3736
SysctlTestModule,
3837
author: "Alex Gaynor and Geoffrey Thomas",
3938
description: "A module for testing sysctls",

tests/sysctl/tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate kernel_module_tests;
2-
31
use std::fs;
42
use std::path::Path;
53

0 commit comments

Comments
 (0)