* [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
@ 2022-03-19 7:05 ayushdevel1325
2022-03-19 7:05 ` [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std Ayush Singh
` (3 more replies)
0 siblings, 4 replies; 10+ messages in thread
From: ayushdevel1325 @ 2022-03-19 7:05 UTC (permalink / raw)
To: devel
CC Jiewen Yao
This is my 2nd email about this patch to fix edkii-rust branch in
edk2-staging repo, this time hopefully following contributing procedure
better.
I have tried to to fix RustPkg/Test/HelloWorld,
RustPkg/Test/HelloWorld2, RustPkg/Test/TestRustLangApp, and
RustPkg/Test/TestRustLangLib. This also meant fixing
RustPkg/Library/UefiRustIntrinsicLib and
RustPkg/Library/UefiRustAllocationLib.
It is also not possible to build this branch with gcc-11 since that will
require a rebase to edk2/master, but I am not sure how that can be done
since edk2-staging/master does not track edk2/master like it is supposed
to according to the edk2-staging/about branch.
My working repository for these commits can be found at:
https://github.com/Ayush1325/edk2-staging/tree/edkii-rust-fix-v1
Ayush Singh (3):
RustPkg/Test: Replace cargo-xbuild with build-std
RustPkg/Test/TestRustLangLib: Fix Building
RustPkg/Test/TestRustLangApp: Fix building
RustPkg/Library/UefiRustAllocationLib/src/lib.rs | 53 ++--
RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs | 8 -
RustPkg/Test/HelloWorld/.cargo/config.toml | 3 +
RustPkg/Test/HelloWorld2/.cargo/config.toml | 3 +
RustPkg/Test/TestRustLangApp/.cargo/config.toml | 3 +
RustPkg/Test/TestRustLangApp/src/main.rs | 95 +++----
RustPkg/Test/TestRustLangLib/.cargo/config.toml | 3 +
RustPkg/Test/TestRustLangLib/src/lib.rs | 264 ++++++++------------
8 files changed, 186 insertions(+), 246 deletions(-)
create mode 100644 RustPkg/Test/HelloWorld/.cargo/config.toml
create mode 100644 RustPkg/Test/HelloWorld2/.cargo/config.toml
create mode 100644 RustPkg/Test/TestRustLangApp/.cargo/config.toml
create mode 100644 RustPkg/Test/TestRustLangLib/.cargo/config.toml
--
2.35.1
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std
2022-03-19 7:05 [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging ayushdevel1325
@ 2022-03-19 7:05 ` Ayush Singh
2022-03-19 7:05 ` [PATCH v1 2/3] RustPkg/Test/TestRustLangLib: Fix Building Ayush Singh
` (2 subsequent siblings)
3 siblings, 0 replies; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 7:05 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao
From: Ayush Singh <ayushsingh1325@gmail.com>
Tests Migrated:
- Test/HelloWorld
- Test/HelloWorld2
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
RustPkg/Test/HelloWorld/.cargo/config.toml | 3 +++
RustPkg/Test/HelloWorld2/.cargo/config.toml | 3 +++
2 files changed, 6 insertions(+)
diff --git a/RustPkg/Test/HelloWorld/.cargo/config.toml b/RustPkg/Test/HelloWorld/.cargo/config.toml
new file mode 100644
index 000000000000..3d6a3ff35cd7
--- /dev/null
+++ b/RustPkg/Test/HelloWorld/.cargo/config.toml
@@ -0,0 +1,3 @@
+[unstable]
+build-std = ["core", "compiler_builtins"]
+build-std-features = ["compiler-builtins-mem"]
diff --git a/RustPkg/Test/HelloWorld2/.cargo/config.toml b/RustPkg/Test/HelloWorld2/.cargo/config.toml
new file mode 100644
index 000000000000..3d6a3ff35cd7
--- /dev/null
+++ b/RustPkg/Test/HelloWorld2/.cargo/config.toml
@@ -0,0 +1,3 @@
+[unstable]
+build-std = ["core", "compiler_builtins"]
+build-std-features = ["compiler-builtins-mem"]
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v1 2/3] RustPkg/Test/TestRustLangLib: Fix Building
2022-03-19 7:05 [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging ayushdevel1325
2022-03-19 7:05 ` [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std Ayush Singh
@ 2022-03-19 7:05 ` Ayush Singh
2022-03-19 7:05 ` [PATCH v1 3/3] RustPkg/Test/TestRustLangApp: Fix building Ayush Singh
2022-03-19 8:40 ` [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging Marvin Häuser
3 siblings, 0 replies; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 7:05 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao
From: Ayush Singh <ayushsingh1325@gmail.com>
Removed the Alloc trait usage which seems to have been removed from
Rust now.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
RustPkg/Library/UefiRustAllocationLib/src/lib.rs | 53 ++--
RustPkg/Test/TestRustLangLib/.cargo/config.toml | 3 +
RustPkg/Test/TestRustLangLib/src/lib.rs | 264 ++++++++------------
3 files changed, 137 insertions(+), 183 deletions(-)
diff --git a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs b/RustPkg/Library/UefiRustAllocationLib/src/lib.rs
index f369e1bb170b..6a65f0a5f988 100644
--- a/RustPkg/Library/UefiRustAllocationLib/src/lib.rs
+++ b/RustPkg/Library/UefiRustAllocationLib/src/lib.rs
@@ -15,44 +15,42 @@
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(alloc_error_handler)]
-
#![cfg_attr(not(test), no_std)]
-
#![allow(unused)]
extern crate uefi_rust_panic_lib;
-use core::alloc::{GlobalAlloc, Layout, Alloc};
-use r_efi::efi;
-use r_efi::efi::{Status};
+use core::alloc::{GlobalAlloc, Layout};
use core::ffi::c_void;
+use r_efi::efi;
+use r_efi::efi::Status;
pub struct MyAllocator;
-static mut ST : *mut efi::SystemTable = core::ptr::null_mut();
-static mut BS : *mut efi::BootServices = core::ptr::null_mut();
+static mut ST: *mut efi::SystemTable = core::ptr::null_mut();
+static mut BS: *mut efi::BootServices = core::ptr::null_mut();
unsafe impl GlobalAlloc for MyAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
- let size = layout.size();
- let align = layout.align();
- if align > 8 {
- return core::ptr::null_mut();
- }
+ let size = layout.size();
+ let align = layout.align();
+ if align > 8 {
+ return core::ptr::null_mut();
+ }
- let mut address : *mut c_void = core::ptr::null_mut();
- let status = ((*BS).allocate_pool) (
- efi::MemoryType::BootServicesData,
- size,
- &mut address as *mut *mut c_void
- );
- if status != Status::SUCCESS {
- return core::ptr::null_mut();
- }
- address as *mut u8
+ let mut address: *mut c_void = core::ptr::null_mut();
+ let status = ((*BS).allocate_pool)(
+ efi::MemoryType::BootServicesData,
+ size,
+ &mut address as *mut *mut c_void,
+ );
+ if status != Status::SUCCESS {
+ return core::ptr::null_mut();
+ }
+ address as *mut u8
}
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
- ((*BS).free_pool) (ptr as *mut c_void);
+ ((*BS).free_pool)(ptr as *mut c_void);
}
}
@@ -60,14 +58,13 @@ unsafe impl GlobalAlloc for MyAllocator {
static ALLOCATOR: MyAllocator = MyAllocator;
#[alloc_error_handler]
-fn alloc_error_handler(layout: core::alloc::Layout) -> !
-{
+fn alloc_error_handler(layout: core::alloc::Layout) -> ! {
loop {}
}
-pub extern fn init(system_table: *mut efi::SystemTable) {
+pub extern "C" fn init(system_table: *mut efi::SystemTable) {
unsafe {
- ST = system_table;
- BS = (*ST).boot_services;
+ ST = system_table;
+ BS = (*ST).boot_services;
}
}
diff --git a/RustPkg/Test/TestRustLangLib/.cargo/config.toml b/RustPkg/Test/TestRustLangLib/.cargo/config.toml
new file mode 100644
index 000000000000..422bf9d2ab4e
--- /dev/null
+++ b/RustPkg/Test/TestRustLangLib/.cargo/config.toml
@@ -0,0 +1,3 @@
+[unstable]
+build-std = ["core", "compiler_builtins", "alloc"]
+build-std-features = ["compiler-builtins-mem"]
diff --git a/RustPkg/Test/TestRustLangLib/src/lib.rs b/RustPkg/Test/TestRustLangLib/src/lib.rs
index ee3a0d7cc83e..888733232b71 100644
--- a/RustPkg/Test/TestRustLangLib/src/lib.rs
+++ b/RustPkg/Test/TestRustLangLib/src/lib.rs
@@ -14,24 +14,22 @@
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
-#![feature(core_panic_info)]
-
+#![feature(slice_ptr_get)]
#![cfg_attr(not(test), no_std)]
-
#![allow(unused)]
mod mem;
use r_efi::efi;
-use r_efi::efi::{Status};
+use r_efi::efi::Status;
-extern {
- fn AllocatePool (Size: usize) -> *mut c_void;
- fn FreePool (Buffer: *mut c_void);
+extern "C" {
+ fn AllocatePool(Size: usize) -> *mut c_void;
+ fn FreePool(Buffer: *mut c_void);
}
-use core::panic::PanicInfo;
use core::ffi::c_void;
+use core::panic::PanicInfo;
use core::mem::size_of;
use core::mem::transmute;
@@ -40,30 +38,22 @@ use core::slice;
use core::slice::from_raw_parts;
use core::slice::from_raw_parts_mut;
-extern crate uefi_rust_panic_lib;
extern crate uefi_rust_allocation_lib;
+extern crate uefi_rust_panic_lib;
extern crate alloc;
-use alloc::vec::Vec;
+use alloc::alloc::{handle_alloc_error, Allocator, Global, Layout};
use alloc::boxed::Box;
-use alloc::{
- alloc::{handle_alloc_error, Alloc, Global, Layout},
-};
-
+use alloc::vec::Vec;
#[no_mangle]
#[export_name = "TestIntegerOverflow"]
-pub extern fn test_integer_overflow (
- buffer_size: usize,
- width : u32,
- height : u32,
- ) -> Status
-{
+pub extern "C" fn test_integer_overflow(buffer_size: usize, width: u32, height: u32) -> Status {
let data_size = width * height * 4;
if data_size as usize > buffer_size {
- return Status::UNSUPPORTED;
+ return Status::UNSUPPORTED;
}
Status::SUCCESS
@@ -71,26 +61,24 @@ pub extern fn test_integer_overflow (
#[no_mangle]
#[export_name = "TestIntegerCheckedOverflow"]
-pub extern fn test_integer_checked_overflow (
+pub extern "C" fn test_integer_checked_overflow(
buffer_size: usize,
- width : u32,
- height : u32,
- ) -> Status
-{
-
+ width: u32,
+ height: u32,
+) -> Status {
let mut data_size: u32 = 0;
match width.checked_mul(height) {
- Some(size) => {data_size = size},
- None => {return Status::INVALID_PARAMETER},
+ Some(size) => data_size = size,
+ None => return Status::INVALID_PARAMETER,
}
match data_size.checked_mul(4) {
- Some(size) => {data_size = size},
- None => {return Status::INVALID_PARAMETER},
+ Some(size) => data_size = size,
+ None => return Status::INVALID_PARAMETER,
}
if data_size as usize > buffer_size {
- return Status::UNSUPPORTED;
+ return Status::UNSUPPORTED;
}
Status::SUCCESS
@@ -98,31 +86,27 @@ pub extern fn test_integer_checked_overflow (
#[no_mangle]
#[export_name = "TestIntegerCast"]
-pub extern fn test_integer_cast (
- buffer_size: u64,
- ) -> u32
-{
- let data_size : u32 = buffer_size as u32;
+pub extern "C" fn test_integer_cast(buffer_size: u64) -> u32 {
+ let data_size: u32 = buffer_size as u32;
data_size
}
-extern {
- fn ExternInit(Data: *mut usize);
+extern "C" {
+ fn ExternInit(Data: *mut usize);
}
#[no_mangle]
#[export_name = "TestUninitializedVariable"]
-pub extern fn test_uninitializd_variable (
- index: usize,
- ) -> usize
-{
- let mut data : usize = 1;
+pub extern "C" fn test_uninitializd_variable(index: usize) -> usize {
+ let mut data: usize = 1;
if index > 10 {
- data = 0;
+ data = 0;
}
- unsafe { ExternInit (&mut data ); }
+ unsafe {
+ ExternInit(&mut data);
+ }
data = data + 1;
@@ -131,11 +115,8 @@ pub extern fn test_uninitializd_variable (
#[no_mangle]
#[export_name = "TestArrayOutOfRange"]
-pub extern fn test_array_out_of_range (
- index: usize,
- ) -> usize
-{
- let mut data : [u8; 8] = [0; 8];
+pub extern "C" fn test_array_out_of_range(index: usize) -> usize {
+ let mut data: [u8; 8] = [0; 8];
data[index] = 1;
@@ -152,18 +133,21 @@ pub struct TestTable {
#[no_mangle]
#[export_name = "TestBufferOverflow"]
-pub extern fn test_buffer_overflow (
+pub extern "C" fn test_buffer_overflow(
buffer: &mut [u8; 0],
buffer_size: usize,
table: &TestTable,
table_size: usize,
- )
-{
- let mut dest = crate::mem::MemoryRegion::new(buffer as *mut [u8; 0] as usize as u64, buffer_size as u64);
- let mut source = crate::mem::MemoryRegion::new(&table.value as *const [u8; 0] as usize as u64, table_size as u64);
+) {
+ let mut dest =
+ crate::mem::MemoryRegion::new(buffer as *mut [u8; 0] as usize as u64, buffer_size as u64);
+ let mut source = crate::mem::MemoryRegion::new(
+ &table.value as *const [u8; 0] as usize as u64,
+ table_size as u64,
+ );
- for index in 0_u64 .. table.length as u64 {
- dest.write_u8(index, source.read_u8(index));
+ for index in 0_u64..table.length as u64 {
+ dest.write_u8(index, source.read_u8(index));
}
}
@@ -177,59 +161,49 @@ pub struct TestTableFixed {
#[no_mangle]
#[export_name = "TestBufferOverflowFixed"]
-pub extern fn test_buffer_overflow_fixed (
- buffer: &mut [u8; 32],
- table: &TestTableFixed,
- )
-{
- (*buffer)[0_usize..(table.length as usize)].copy_from_slice(
- &table.value[0_usize..(table.length as usize)]
- );
+pub extern "C" fn test_buffer_overflow_fixed(buffer: &mut [u8; 32], table: &TestTableFixed) {
+ (*buffer)[0_usize..(table.length as usize)]
+ .copy_from_slice(&table.value[0_usize..(table.length as usize)]);
}
-fn get_buffer<'a> () -> Option<&'a mut TestTableFixed>
-{
- let ptr : *mut c_void = unsafe { AllocatePool (size_of::<TestTableFixed>()) };
+fn get_buffer<'a>() -> Option<&'a mut TestTableFixed> {
+ let ptr: *mut c_void = unsafe { AllocatePool(size_of::<TestTableFixed>()) };
if ptr.is_null() {
- return None;
+ return None;
}
- let buffer : &mut TestTableFixed = unsafe { core::mem::transmute::<*mut c_void, &mut TestTableFixed>(ptr) };
+ let buffer: &mut TestTableFixed =
+ unsafe { core::mem::transmute::<*mut c_void, &mut TestTableFixed>(ptr) };
Some(buffer)
}
-fn release_buffer (test_table : &mut TestTableFixed)
-{
- test_table.r#type = 0;
- unsafe { FreePool (test_table as *mut TestTableFixed as *mut c_void) ; }
+fn release_buffer(test_table: &mut TestTableFixed) {
+ test_table.r#type = 0;
+ unsafe {
+ FreePool(test_table as *mut TestTableFixed as *mut c_void);
+ }
}
#[no_mangle]
#[export_name = "TestBufferDrop"]
-pub extern fn test_buffer_drop (
-
- )
-{
- match get_buffer () {
- Some(buffer) => {
- buffer.r#type = 1;
- release_buffer(buffer);
- drop (buffer); // This is required.
- //buffer.r#type = 1; // error
- },
- None => {},
+pub extern "C" fn test_buffer_drop() {
+ match get_buffer() {
+ Some(buffer) => {
+ buffer.r#type = 1;
+ release_buffer(buffer);
+ drop(buffer); // This is required.
+ //buffer.r#type = 1; // error
+ }
+ None => {}
}
}
#[no_mangle]
#[export_name = "TestBufferBorrow"]
-pub extern fn test_buffer_borrow (
- test_table : &mut TestTableFixed
- )
-{
- let test_table2 : &mut TestTableFixed = test_table;
+pub extern "C" fn test_buffer_borrow(test_table: &mut TestTableFixed) {
+ let test_table2: &mut TestTableFixed = test_table;
test_table2.r#type = 1;
- let test_table3 : &mut [u8; 64] = &mut test_table.value;
+ let test_table3: &mut [u8; 64] = &mut test_table.value;
test_table3[63] = 0;
//test_table2.r#type = 2; // error
@@ -237,44 +211,38 @@ pub extern fn test_buffer_borrow (
#[no_mangle]
#[export_name = "TestBufferAlloc"]
-pub extern fn test_buffer_alloc (
-
- )
-{
+pub extern "C" fn test_buffer_alloc() {
let layout = unsafe { core::alloc::Layout::from_size_align_unchecked(32, 4) };
unsafe {
- match Global.alloc (layout) {
- Ok(buffer) => {
- let mut box_buffer = Box::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size()));
- box_buffer[0] = 1;
- Global.dealloc (buffer, layout);
- drop (buffer); // It is useless
- box_buffer[0] = 1; // cannot catch
- },
- Err(_) => handle_alloc_error (layout),
- }
+ match Global.allocate(layout) {
+ Ok(mut buffer) => {
+ let mut box_buffer = Box::from_raw(buffer.as_mut());
+ box_buffer[0] = 1;
+ Global.deallocate(buffer.as_non_null_ptr(), layout);
+ drop(buffer); // It is useless
+ box_buffer[0] = 1; // cannot catch
+ }
+ Err(_) => handle_alloc_error(layout),
+ }
}
let layout = core::alloc::Layout::new::<u32>();
unsafe {
- match Global.alloc (layout) {
- Ok(buffer) => {
- Global.dealloc (buffer, layout);
- },
- Err(_) => handle_alloc_error (layout),
- }
+ match Global.allocate(layout) {
+ Ok(buffer) => {
+ Global.deallocate(buffer.as_non_null_ptr(), layout);
+ }
+ Err(_) => handle_alloc_error(layout),
+ }
}
}
-fn get_box (
- r#type: u32
- ) -> Box<TestTableFixed>
-{
- let mut a = Box::new(TestTableFixed{
- r#type: 0,
- length: size_of::<TestTableFixed>() as u32,
- value: [0; 64]
- }); // it will call __rust_alloc().
+fn get_box(r#type: u32) -> Box<TestTableFixed> {
+ let mut a = Box::new(TestTableFixed {
+ r#type: 0,
+ length: size_of::<TestTableFixed>() as u32,
+ value: [0; 64],
+ }); // it will call __rust_alloc().
a.r#type = r#type;
a
@@ -282,35 +250,26 @@ fn get_box (
#[no_mangle]
#[export_name = "TestBoxAlloc"]
-pub extern fn test_box_alloc (
- r#type: u32
- ) -> Box<TestTableFixed>
-{
- let mut a = get_box(1);
+pub extern "C" fn test_box_alloc(r#type: u32) -> Box<TestTableFixed> {
+ let mut a = get_box(1);
- a.r#type = r#type;
+ a.r#type = r#type;
- //test_box_free(a); // build fail.
+ //test_box_free(a); // build fail.
- let b = a;
- b
+ let b = a;
+ b
}
#[no_mangle]
#[export_name = "TestBoxFree"]
-pub extern fn test_box_free (
- buffer: Box<TestTableFixed>
- )
-{
- // it will call __rust_dealloc()
+pub extern "C" fn test_box_free(buffer: Box<TestTableFixed>) {
+ // it will call __rust_dealloc()
}
#[no_mangle]
#[export_name = "TestBoxAllocFail"]
-pub extern fn test_box_alloc_fail (
- size: u32
- ) -> Box<[u8; 0x800]>
-{
+pub extern "C" fn test_box_alloc_fail(size: u32) -> Box<[u8; 0x800]> {
let mut a = Box::new([0_u8; 0x800]); // it will call __rust_alloc().
a
@@ -318,22 +277,17 @@ pub extern fn test_box_alloc_fail (
#[no_mangle]
#[export_name = "TestBoxConvert"]
-pub extern fn test_box_convert (
- size: usize
- ) -> *mut u8
-{
+pub extern "C" fn test_box_convert(size: usize) -> *mut u8 {
let layout = unsafe { core::alloc::Layout::from_size_align_unchecked(size, 4) };
unsafe {
- match Global.alloc (layout) {
- Ok(buffer) => {
- let mut box_buffer = Box::<u8>::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size()) as *mut [u8] as *mut u8 );
- Global.dealloc (buffer, layout);
- *box_buffer = 1;
- Box::<u8>::into_raw(box_buffer)
- },
- Err(_) => handle_alloc_error (layout),
- }
+ match Global.allocate(layout) {
+ Ok(buffer) => {
+ let mut box_buffer = Box::<u8>::from_raw(buffer.as_mut_ptr());
+ Global.deallocate(buffer.as_non_null_ptr(), layout);
+ *box_buffer = 1;
+ Box::<u8>::into_raw(box_buffer)
+ }
+ Err(_) => handle_alloc_error(layout),
+ }
}
-
-
}
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v1 3/3] RustPkg/Test/TestRustLangApp: Fix building
2022-03-19 7:05 [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging ayushdevel1325
2022-03-19 7:05 ` [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std Ayush Singh
2022-03-19 7:05 ` [PATCH v1 2/3] RustPkg/Test/TestRustLangLib: Fix Building Ayush Singh
@ 2022-03-19 7:05 ` Ayush Singh
2022-03-19 8:40 ` [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging Marvin Häuser
3 siblings, 0 replies; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 7:05 UTC (permalink / raw)
To: devel; +Cc: Jiewen Yao
Removed defination of _fltused from
RustPkg/Library/UefiRustIntrinsicLib since compiler_builtins now
provides one
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
---
RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs | 8 --
RustPkg/Test/TestRustLangApp/.cargo/config.toml | 3 +
RustPkg/Test/TestRustLangApp/src/main.rs | 95 +++++++++-----------
3 files changed, 43 insertions(+), 63 deletions(-)
diff --git a/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs b/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs
index c2341e9a65af..2bfdc524a11c 100644
--- a/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs
+++ b/RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs
@@ -12,15 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-
#![cfg_attr(not(test), no_std)]
-
#![allow(unused)]
-#[used]
-#[no_mangle]
-pub static _fltused : i32 = 0;
-
extern crate uefi_rust_panic_lib;
-
-
diff --git a/RustPkg/Test/TestRustLangApp/.cargo/config.toml b/RustPkg/Test/TestRustLangApp/.cargo/config.toml
new file mode 100644
index 000000000000..422bf9d2ab4e
--- /dev/null
+++ b/RustPkg/Test/TestRustLangApp/.cargo/config.toml
@@ -0,0 +1,3 @@
+[unstable]
+build-std = ["core", "compiler_builtins", "alloc"]
+build-std-features = ["compiler-builtins-mem"]
diff --git a/RustPkg/Test/TestRustLangApp/src/main.rs b/RustPkg/Test/TestRustLangApp/src/main.rs
index 9dcea4fa5c4e..72bb12e16adf 100644
--- a/RustPkg/Test/TestRustLangApp/src/main.rs
+++ b/RustPkg/Test/TestRustLangApp/src/main.rs
@@ -13,120 +13,105 @@
// limitations under the License.
#![crate_type = "staticlib"]
-
#![feature(alloc_layout_extra)]
#![feature(allocator_api)]
#![feature(alloc_error_handler)]
-#![feature(core_panic_info)]
-#![feature(asm)]
-
#![cfg_attr(not(test), no_std)]
#![no_main]
-
#![allow(unused)]
mod mem;
extern crate test_rust_lang_lib;
+extern crate uefi_rust_allocation_lib;
extern crate uefi_rust_intrinsic_lib;
extern crate uefi_rust_panic_lib;
-extern crate uefi_rust_allocation_lib;
use r_efi::efi;
-use r_efi::efi::{Status};
+use r_efi::efi::Status;
-use core::panic::PanicInfo;
use core::ffi::c_void;
+use core::panic::PanicInfo;
use core::mem::size_of;
use core::mem::transmute;
use core::slice::from_raw_parts;
-
-static mut ST : *mut efi::SystemTable = core::ptr::null_mut();
-static mut BS : *mut efi::BootServices = core::ptr::null_mut();
+static mut ST: *mut efi::SystemTable = core::ptr::null_mut();
+static mut BS: *mut efi::BootServices = core::ptr::null_mut();
extern crate alloc;
-use alloc::vec::Vec;
use alloc::boxed::Box;
-
+use alloc::vec::Vec;
#[no_mangle]
#[export_name = "AllocatePool"]
-extern fn AllocatePool (size: usize) -> *mut c_void
-{
- let mut address : *mut c_void = core::ptr::null_mut();
-
- let status = unsafe { ((*BS).allocate_pool) (
- efi::MemoryType::BootServicesData,
- size,
- &mut address as *mut *mut c_void
- ) } ;
- if status != Status::SUCCESS {
+extern "C" fn AllocatePool(size: usize) -> *mut c_void {
+ let mut address: *mut c_void = core::ptr::null_mut();
+
+ let status = unsafe {
+ ((*BS).allocate_pool)(
+ efi::MemoryType::BootServicesData,
+ size,
+ &mut address as *mut *mut c_void,
+ )
+ };
+ if status != Status::SUCCESS {
return core::ptr::null_mut();
- }
- address as *mut c_void
+ }
+ address as *mut c_void
}
-
-
#[no_mangle]
#[export_name = "AllocateZeroPool"]
-extern fn AllocateZeroPool (size: usize) -> *mut c_void
-{
- let buffer = AllocatePool (size);
+extern "C" fn AllocateZeroPool(size: usize) -> *mut c_void {
+ let buffer = AllocatePool(size);
if buffer == core::ptr::null_mut() {
- return core::ptr::null_mut();
+ return core::ptr::null_mut();
}
- unsafe {core::ptr::write_bytes (buffer, 0, size);}
+ unsafe {
+ core::ptr::write_bytes(buffer, 0, size);
+ }
buffer as *mut c_void
}
-
-
#[no_mangle]
#[export_name = "FreePool"]
-extern fn FreePool (buffer: *mut c_void)
-{
+extern "C" fn FreePool(buffer: *mut c_void) {
unsafe {
- ((*BS).free_pool) (buffer as *mut c_void);
+ ((*BS).free_pool)(buffer as *mut c_void);
}
}
#[no_mangle]
#[export_name = "ExternInit"]
-extern fn ExternInit(data: *mut usize)
-{
-}
-
+extern "C" fn ExternInit(data: *mut usize) {}
#[no_mangle]
-pub extern fn efi_main(handle: efi::Handle, system_table: *mut efi::SystemTable) -> Status
-{
+pub extern "C" fn efi_main(handle: efi::Handle, system_table: *mut efi::SystemTable) -> Status {
uefi_rust_allocation_lib::init(system_table);
unsafe {
- ST = system_table;
- BS = (*ST).boot_services;
+ ST = system_table;
+ BS = (*ST).boot_services;
}
// L"Hello World!/r/n"
- let string_name = & mut [
- 0x48u16, 0x65u16, 0x6cu16, 0x6cu16, 0x6fu16, 0x20u16,
- 0x57u16, 0x6fu16, 0x72u16, 0x6cu16, 0x64u16, 0x21u16,
- 0x0Au16, 0x0Du16, 0x00u16
- ];
+ let string_name = &mut [
+ 0x48u16, 0x65u16, 0x6cu16, 0x6cu16, 0x6fu16, 0x20u16, 0x57u16, 0x6fu16, 0x72u16, 0x6cu16,
+ 0x64u16, 0x21u16, 0x0Au16, 0x0Du16, 0x00u16,
+ ];
unsafe {
- ((*((*ST).con_out)).output_string) (
- unsafe {(*ST).con_out},
- string_name.as_ptr() as *mut efi::Char16,
- );
+ ((*((*ST).con_out)).output_string)(
+ unsafe { (*ST).con_out },
+ string_name.as_ptr() as *mut efi::Char16,
+ );
}
- test_rust_lang_lib::test_integer_overflow (0x10000, 0xFFFFFFFF, 0xFFFFFFFF);
+ test_rust_lang_lib::test_integer_overflow(0x10000, 0xFFFFFFFF, 0xFFFFFFFF);
Status::SUCCESS
}
--
2.35.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 7:05 [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging ayushdevel1325
` (2 preceding siblings ...)
2022-03-19 7:05 ` [PATCH v1 3/3] RustPkg/Test/TestRustLangApp: Fix building Ayush Singh
@ 2022-03-19 8:40 ` Marvin Häuser
2022-03-19 8:46 ` Ayush Singh
2022-03-19 13:59 ` Yao, Jiewen
3 siblings, 2 replies; 10+ messages in thread
From: Marvin Häuser @ 2022-03-19 8:40 UTC (permalink / raw)
To: devel, ayushdevel1325; +Cc: jiewen.yao
> On 19. Mar 2022, at 08:06, Ayush Singh <ayushdevel1325@gmail.com> wrote:
>
> CC Jiewen Yao
You didn’t actually CC, done.
Best regards,
Marvin
>
> This is my 2nd email about this patch to fix edkii-rust branch in
> edk2-staging repo, this time hopefully following contributing procedure
> better.
>
> I have tried to to fix RustPkg/Test/HelloWorld,
> RustPkg/Test/HelloWorld2, RustPkg/Test/TestRustLangApp, and
> RustPkg/Test/TestRustLangLib. This also meant fixing
> RustPkg/Library/UefiRustIntrinsicLib and
> RustPkg/Library/UefiRustAllocationLib.
>
> It is also not possible to build this branch with gcc-11 since that will
> require a rebase to edk2/master, but I am not sure how that can be done
> since edk2-staging/master does not track edk2/master like it is supposed
> to according to the edk2-staging/about branch.
>
> My working repository for these commits can be found at:
> https://github.com/Ayush1325/edk2-staging/tree/edkii-rust-fix-v1
>
> Ayush Singh (3):
> RustPkg/Test: Replace cargo-xbuild with build-std
> RustPkg/Test/TestRustLangLib: Fix Building
> RustPkg/Test/TestRustLangApp: Fix building
>
> RustPkg/Library/UefiRustAllocationLib/src/lib.rs | 53 ++--
> RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs | 8 -
> RustPkg/Test/HelloWorld/.cargo/config.toml | 3 +
> RustPkg/Test/HelloWorld2/.cargo/config.toml | 3 +
> RustPkg/Test/TestRustLangApp/.cargo/config.toml | 3 +
> RustPkg/Test/TestRustLangApp/src/main.rs | 95 +++----
> RustPkg/Test/TestRustLangLib/.cargo/config.toml | 3 +
> RustPkg/Test/TestRustLangLib/src/lib.rs | 264 ++++++++------------
> 8 files changed, 186 insertions(+), 246 deletions(-)
> create mode 100644 RustPkg/Test/HelloWorld/.cargo/config.toml
> create mode 100644 RustPkg/Test/HelloWorld2/.cargo/config.toml
> create mode 100644 RustPkg/Test/TestRustLangApp/.cargo/config.toml
> create mode 100644 RustPkg/Test/TestRustLangLib/.cargo/config.toml
>
> --
> 2.35.1
>
>
>
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 8:40 ` [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging Marvin Häuser
@ 2022-03-19 8:46 ` Ayush Singh
2022-03-19 13:59 ` Yao, Jiewen
1 sibling, 0 replies; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 8:46 UTC (permalink / raw)
To: Marvin Häuser, devel
[-- Attachment #1: Type: text/plain, Size: 170 bytes --]
I see. While the other mails got the CC from the commits, the cover letter also needs to do a CC separately. Will keep this in mind from the next commit.
Ayush Singh
[-- Attachment #2: Type: text/html, Size: 950 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 8:40 ` [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging Marvin Häuser
2022-03-19 8:46 ` Ayush Singh
@ 2022-03-19 13:59 ` Yao, Jiewen
2022-03-19 14:14 ` Ayush Singh
1 sibling, 1 reply; 10+ messages in thread
From: Yao, Jiewen @ 2022-03-19 13:59 UTC (permalink / raw)
To: devel@edk2.groups.io, mhaeuser@posteo.de,
ayushdevel1325@gmail.com
Thank you very much Marvin and Ayush.
Glad you have interest on Rust.
May I know what is your goal for this patch? Do you just want to make it pass build?
Or want to work on something more?
Currently, we did not work actively on https://github.com/tianocore/edk2-staging/tree/edkii-rust.
Instead we are thinking an EDKII independent lightweight rust-based firmware - https://github.com/jyao1/rust-firmware.
Would you mind let me know what is your purpose? I am happy to discuss more.
Thank you
Yao Jiewen
> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Marvin
> Häuser
> Sent: Saturday, March 19, 2022 4:40 PM
> To: devel@edk2.groups.io; ayushdevel1325@gmail.com
> Cc: Yao, Jiewen <jiewen.yao@intel.com>
> Subject: Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch
> edk2-staging
>
>
>
> > On 19. Mar 2022, at 08:06, Ayush Singh <ayushdevel1325@gmail.com> wrote:
> >
> > CC Jiewen Yao
>
> You didn’t actually CC, done.
>
> Best regards,
> Marvin
>
> >
> > This is my 2nd email about this patch to fix edkii-rust branch in
> > edk2-staging repo, this time hopefully following contributing procedure
> > better.
> >
> > I have tried to to fix RustPkg/Test/HelloWorld,
> > RustPkg/Test/HelloWorld2, RustPkg/Test/TestRustLangApp, and
> > RustPkg/Test/TestRustLangLib. This also meant fixing
> > RustPkg/Library/UefiRustIntrinsicLib and
> > RustPkg/Library/UefiRustAllocationLib.
> >
> > It is also not possible to build this branch with gcc-11 since that will
> > require a rebase to edk2/master, but I am not sure how that can be done
> > since edk2-staging/master does not track edk2/master like it is supposed
> > to according to the edk2-staging/about branch.
> >
> > My working repository for these commits can be found at:
> > https://github.com/Ayush1325/edk2-staging/tree/edkii-rust-fix-v1
> >
> > Ayush Singh (3):
> > RustPkg/Test: Replace cargo-xbuild with build-std
> > RustPkg/Test/TestRustLangLib: Fix Building
> > RustPkg/Test/TestRustLangApp: Fix building
> >
> > RustPkg/Library/UefiRustAllocationLib/src/lib.rs | 53 ++--
> > RustPkg/Library/UefiRustIntrinsicLib/src/lib.rs | 8 -
> > RustPkg/Test/HelloWorld/.cargo/config.toml | 3 +
> > RustPkg/Test/HelloWorld2/.cargo/config.toml | 3 +
> > RustPkg/Test/TestRustLangApp/.cargo/config.toml | 3 +
> > RustPkg/Test/TestRustLangApp/src/main.rs | 95 +++----
> > RustPkg/Test/TestRustLangLib/.cargo/config.toml | 3 +
> > RustPkg/Test/TestRustLangLib/src/lib.rs | 264 ++++++++------------
> > 8 files changed, 186 insertions(+), 246 deletions(-)
> > create mode 100644 RustPkg/Test/HelloWorld/.cargo/config.toml
> > create mode 100644 RustPkg/Test/HelloWorld2/.cargo/config.toml
> > create mode 100644 RustPkg/Test/TestRustLangApp/.cargo/config.toml
> > create mode 100644 RustPkg/Test/TestRustLangLib/.cargo/config.toml
> >
> > --
> > 2.35.1
> >
> >
> >
> >
> >
> >
>
>
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 13:59 ` Yao, Jiewen
@ 2022-03-19 14:14 ` Ayush Singh
2022-03-19 14:36 ` Yao, Jiewen
0 siblings, 1 reply; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 14:14 UTC (permalink / raw)
To: Yao, Jiewen, devel
[-- Attachment #1: Type: text/plain, Size: 797 bytes --]
Hello Jiewen,
I am a 2nd year University student and am interested in applying for GSoC 2022. I found the project Tasks-Add-Rust-Support-to-EDK-II ( https://github.com/tianocore/tianocore.github.io/wiki/Tasks-Add-Rust-Support-to-EDK-II ) and it contained links to the edkii-rust repository as being an earlier attempt to do this. So I was trying to update/fix the building of this branch as a kind of task that organizations have for student applications. I wanted to understand the old implementation better anyway since it seemed a good place to start rather than starting from scratch.
I did not know about https://github.com/jyao1/rust-firmware , will take a look at it as well.
My introduction mail can be found here ( https://edk2.groups.io/g/devel/message/87637 ).
Ayush Singh
[-- Attachment #2: Type: text/html, Size: 994 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 14:14 ` Ayush Singh
@ 2022-03-19 14:36 ` Yao, Jiewen
2022-03-19 21:11 ` Ayush Singh
0 siblings, 1 reply; 10+ messages in thread
From: Yao, Jiewen @ 2022-03-19 14:36 UTC (permalink / raw)
To: Ayush Singh, devel@edk2.groups.io; +Cc: Yao, Jiewen
[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]
I see.
Please let me know if you have some idea to continue.
Thank you
Yao, Jiewen
From: Ayush Singh <ayushdevel1325@gmail.com>
Sent: Saturday, March 19, 2022 10:14 PM
To: Yao; Yao, Jiewen <jiewen.yao@intel.com>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
Hello Jiewen,
I am a 2nd year University student and am interested in applying for GSoC 2022. I found the project Tasks-Add-Rust-Support-to-EDK-II<https://github.com/tianocore/tianocore.github.io/wiki/Tasks-Add-Rust-Support-to-EDK-II> and it contained links to the edkii-rust repository as being an earlier attempt to do this. So I was trying to update/fix the building of this branch as a kind of task that organizations have for student applications. I wanted to understand the old implementation better anyway since it seemed a good place to start rather than starting from scratch.
I did not know about https://github.com/jyao1/rust-firmware, will take a look at it as well.
My introduction mail can be found here<https://edk2.groups.io/g/devel/message/87637>.
Ayush Singh
[-- Attachment #2: Type: text/html, Size: 3532 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging
2022-03-19 14:36 ` Yao, Jiewen
@ 2022-03-19 21:11 ` Ayush Singh
0 siblings, 0 replies; 10+ messages in thread
From: Ayush Singh @ 2022-03-19 21:11 UTC (permalink / raw)
To: Yao, Jiewen, devel
[-- Attachment #1: Type: text/plain, Size: 177 bytes --]
Ok,
I would like to ask why edkii-rust was abandoned. Was it simply because of a lack of time or were there some technical limitations/walls that lead to it?
Ayush Singh
[-- Attachment #2: Type: text/html, Size: 194 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2022-03-19 21:11 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-19 7:05 [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging ayushdevel1325
2022-03-19 7:05 ` [PATCH v1 1/3] RustPkg/Test: Replace cargo-xbuild with build-std Ayush Singh
2022-03-19 7:05 ` [PATCH v1 2/3] RustPkg/Test/TestRustLangLib: Fix Building Ayush Singh
2022-03-19 7:05 ` [PATCH v1 3/3] RustPkg/Test/TestRustLangApp: Fix building Ayush Singh
2022-03-19 8:40 ` [edk2-devel] [PATCH v1 0/3]: Fix RustPkg/Tests in edkii-rust branch edk2-staging Marvin Häuser
2022-03-19 8:46 ` Ayush Singh
2022-03-19 13:59 ` Yao, Jiewen
2022-03-19 14:14 ` Ayush Singh
2022-03-19 14:36 ` Yao, Jiewen
2022-03-19 21:11 ` Ayush Singh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox