Re: Rust for RTEMS [was: Re: Interested for GSoC 2023]

2023-03-03 Thread Karel Gardas

On 2/27/23 12:00, Karel Gardas wrote:

On 2/27/23 02:16, Joel Sherrill wrote:

Another GCC related project could be Rust RTEMS Support but I don't
know what that entails beyond turning it on and seeing what goes
wrong. I tried to build it last year and got far enough to decide to
wait before trying again.


Not sure how far you went. The process is generally:

(1) tune Rust compiler to cross-compile correctly for specific 
hardware/os

platform. So basically you get no_std capable compiler

(2) review, patch and by using (1) cross-compile libc

(3) using sources from (1) and (2) build full stage (std enabled) rustc.

(4) tweak and tune tools (rustup/cargo etc.) whenever required to smooth
sharp edges for RTEMS.

Here, I'm nearly finished with (1) for arm-rtems (e.g. cortex-aX not 
cortex-

mX).


Something is running:

silence:/tmp$ cat hello-rtems.rs

#![no_std]
#![no_main]

use core::panic::PanicInfo;
use core::ffi::c_char;
use core::ffi::c_int;

extern "C" {
fn puts(str: *const c_char) -> c_int;
}

#[no_mangle]
pub fn main() -> ! {
unsafe {
puts(b"Rust says hello to hosting RTEMS\n\0".as_ptr() as *const 
i8);

}
loop {}
}

#[panic_handler]
fn panic(_: ) -> ! {
  loop {}
}

silence:/tmp$ /tmp/rustc-rtems-arm/bin/rustc -g -Z verbose 
--target=arm-rtems hello-rtems.rs -lrtemscpu -lrtemsbsp -lrtemsdefaultconfig


silence:/tmp$ file hello-rtems.exe
hello-rtems.exe: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), 
statically linked, with debug_info, not stripped


silence:/tmp$ ~rtems/sfw/qemu-7.2.0/bin/qemu-system-arm -serial null 
-serial mon:stdio -nographic -M xilinx-zynq-a9 -m 512M -kernel 
/tmp/hello-rtems.exe

Rust says hello to hosting RTEMS

QEMU 7.2.0 monitor - type 'help' for more information
(qemu) q
silence:/tmp$


Note: this is hacked rust-lang.org rust compiler, not gccrs project and 
soon to be released GCC 13.


The biggest problem and probably soon to be source of headaches is 
mixture of LLVM's compiler-rt and GCC's libgcc binaries. This means once 
you employ for example arithmetic you need to add
-C link-arg=-Wl,--allow-multiple-definition otherwise you would get 
multiple definitions symbols error.


Karel

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: Rust for RTEMS [was: Re: Interested for GSoC 2023]

2023-02-27 Thread Karel Gardas

On 2/27/23 15:44, Joel Sherrill wrote:



On Mon, Feb 27, 2023 at 5:00 AM Karel Gardas  
wrote:



adjusting subject based on Jan request. Keeping whole Rust relevant
comments in.

On 2/27/23 11:07, jan.som...@dlr.de  wrote:
 >
 >
 >> -Original Message-
 >> From: devel mailto:devel-boun...@rtems.org>> On Behalf Of Karel Gardas
 >> Sent: Montag, 27. Februar 2023 09:16
 >> To: j...@rtems.org ; Vihas Makwana
mailto:makvi...@gmail.com>>
 >> Cc: rtems-de...@rtems.org 
mailto:devel@rtems.org>>
 >> Subject: Re: Interested for GSoC 2023
 >>
 >> On 2/27/23 02:16, Joel Sherrill wrote:
 >>> Another GCC related project could be Rust RTEMS Support but I don't
 >>> know what that entails beyond turning it on and seeing what goes
 >>> wrong. I tried to build it last year and got far enough to
decide to
 >>> wait before trying again.
 >>
 >> Not sure how far you went. The process is generally:
 >>
 >> (1) tune Rust compiler to cross-compile correctly for specific
hardware/os
 >> platform. So basically you get no_std capable compiler


You should be able to compile gcc rust NOW to target CPU-rtems. I would
expect minor tweaking of configuration both in configure scripting and 
likely

in the Rust run-time libraries. For example, with the Standard C++ Library
there are configuration settings for *-rtems which pick the threading and
synchronization model. Rust's run-time adapter with GCC should be similar.


There is a slight misunderstanding going here. I'm not talking about 
gccrs rust frond-end project which got merged into GCC to become part of 
GCC 13 in autumn last year to be released this spring probably. I'm 
talking and AFAIK Jan too about real Rust as distributed/provided by 
https://www.rust-lang.org/.


The messages from gccrs project are kind of mixed and clearly warns that 
even with GCC 13, the front-end would be good just for GCC rust ongoing 
development and not yet for let say Rust code in Linux kernel. I write 
that not to play that attempt down, in fact gccrs people work is 
outstanding, I write that just to remark that it may take some time 
before it's ready for general "consumption".


Hence, when investigating Rust for RTEMS, I went to rust-lang.org and 
investigated that because after all, this is still reference Rust 
implementation...



Not sure if I did not confused you with my (2) libc remark. I of course
mean Rust's libc (that means rust code) to be build on top of
RTEMS/Newlib/libbsd combination. It'll be interesting project
especially
if the requirement later would be to support both binary targets: e.g.
RTEMS without libbsd (for smaller systems) and RTEMS with libbsd for
full-blown configuration. Anyway, for now, I would start with libbsd as
this should make project proceeding faster IMHO.


You shouldn't need RTEMS or libbsd built until you link real executables
you want to run. All needed POSIX headers are present from newlib.


But I'm at the stage I'd like to link my Rust hello world with RTEMS 
BSP, that's what someone expects at the end anyway. :-)



I was test building rust just like C, C++, and Ada. Build the toolchain and
then build RTEMS.


So you liked rust + RTEMS well? Cool!

Karel

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: Rust for RTEMS [was: Re: Interested for GSoC 2023]

2023-02-27 Thread Joel Sherrill
On Mon, Feb 27, 2023 at 5:00 AM Karel Gardas 
wrote:

>
> adjusting subject based on Jan request. Keeping whole Rust relevant
> comments in.
>
> On 2/27/23 11:07, jan.som...@dlr.de wrote:
> >
> >
> >> -Original Message-
> >> From: devel  On Behalf Of Karel Gardas
> >> Sent: Montag, 27. Februar 2023 09:16
> >> To: j...@rtems.org; Vihas Makwana 
> >> Cc: rtems-de...@rtems.org 
> >> Subject: Re: Interested for GSoC 2023
> >>
> >> On 2/27/23 02:16, Joel Sherrill wrote:
> >>> Another GCC related project could be Rust RTEMS Support but I don't
> >>> know what that entails beyond turning it on and seeing what goes
> >>> wrong. I tried to build it last year and got far enough to decide to
> >>> wait before trying again.
> >>
> >> Not sure how far you went. The process is generally:
> >>
> >> (1) tune Rust compiler to cross-compile correctly for specific
> hardware/os
> >> platform. So basically you get no_std capable compiler
>

You should be able to compile gcc rust NOW to target CPU-rtems. I would
expect minor tweaking of configuration both in configure scripting and
likely
in the Rust run-time libraries. For example, with the Standard C++ Library
there are configuration settings for *-rtems which pick the threading and
synchronization model. Rust's run-time adapter with GCC should be similar.


> >>
> >> (2) review, patch and by using (1) cross-compile libc
>

Not a huge deal since you can add Rust to a standard gcc build
by adding rust to the "--enable-languages" argument on configure.

It is basically a standard cross gcc-rtems build with rust added to
the languages.



> >>
> >> (3) using sources from (1) and (2) build full stage (std enabled) rustc.



> >>
> >> (4) tweak and tune tools (rustup/cargo etc.) whenever required to smooth
> >> sharp edges for RTEMS.
>

Yep. May also uncover some small alligators in the standard Rust code which
is too Linux centric.


> >>
> >> Here, I'm nearly finished with (1) for arm-rtems (e.g. cortex-aX not
> cortex-
> >> mX).
>

Is it using the "one tree" build and build the C library at the same time?

I attached my scripts to do this. Be warned they are what is jokingly
referred
to as "j scripts" which means they are helpers for me but not necessarily
for external human consumption. :)

Generally you will have to tweak them at the top for install point,
binutils and
gcc source tree name, etc. I generally:

+ clone binutils-gdb, newlib, and gcc
+ sym link newlib/newlib and newlib/libgloss into gcc's tree
+ run contrib/download_prerequesites in the top of gcc's source tree

j-bin gets you an install of binutils and gdb
j-gcc layers on gcc

You likely want to make sure the script --disable-multilib to speed up
the builds and work with an architecture/BSP where the default
multilib works together. sparc and aarch64 meet that rule. Building
the multlibs is time consuming and counterproductive when just
working through basic breakages.


> >>
> >
> > Hi Karel,
> >
> > Very interesting work. I am currently trying to reach the same goal.
> > The steps I came up with are a bit different:
> > A.) Build working llvm toolchain for RTEMS (figure out all flags etc.,
> maybe building RTEMS with llvm as a bonus)
> > B.) Build rustc with the "RTEMS-llvm" as backend
>
> Honestly I'm not so sure (A) and (B) are necessary for rustc port. Or
> perhaps I do not precisely follow what you mean, but IMHO what you need
> is to get ABI and linking with RTEMS binaries right. And this applies
> also to RTEMS being build by GCC toolchain. This is objective of my (1)
> work.
>
> > C.) Start with no_std and then inch forward to building the stdlib
> >
> > I work currently on step A (see my llvm experiments in the other thread)
> and started to look at the build stages for rustc.
> > If you have any tips for the configuration from your step (1), it would
> be greatly appreciated.
> > My hope is that with the results of step A I can reuse the libc from the
> standard rtems-gcc build environment as this is provided conveniently via
> rsb.
>
> Not sure if I did not confused you with my (2) libc remark. I of course
> mean Rust's libc (that means rust code) to be build on top of
> RTEMS/Newlib/libbsd combination. It'll be interesting project especially
> if the requirement later would be to support both binary targets: e.g.
> RTEMS without libbsd (for smaller systems) and RTEMS with libbsd for
> full-blown configuration. Anyway, for now, I would start with libbsd as
> this should make project proceeding faster IMHO.
>

You shouldn't need RTEMS or libbsd built until you link real executables
you want to run. All needed POSIX headers are present from newlib.

I was test building rust just like C, C++, and Ada. Build the toolchain and
then build RTEMS.

>
> > I am really looking forward to seeing rust supported on RTEMS.
>
> Me too!
>
> Karel
>
>


j-bin
Description: Binary data


j-gcc
Description: Binary data
___
devel mailing list
devel@rtems.org

Rust for RTEMS [was: Re: Interested for GSoC 2023]

2023-02-27 Thread Karel Gardas



adjusting subject based on Jan request. Keeping whole Rust relevant 
comments in.


On 2/27/23 11:07, jan.som...@dlr.de wrote:




-Original Message-
From: devel  On Behalf Of Karel Gardas
Sent: Montag, 27. Februar 2023 09:16
To: j...@rtems.org; Vihas Makwana 
Cc: rtems-de...@rtems.org 
Subject: Re: Interested for GSoC 2023

On 2/27/23 02:16, Joel Sherrill wrote:

Another GCC related project could be Rust RTEMS Support but I don't
know what that entails beyond turning it on and seeing what goes
wrong. I tried to build it last year and got far enough to decide to
wait before trying again.


Not sure how far you went. The process is generally:

(1) tune Rust compiler to cross-compile correctly for specific hardware/os
platform. So basically you get no_std capable compiler

(2) review, patch and by using (1) cross-compile libc

(3) using sources from (1) and (2) build full stage (std enabled) rustc.

(4) tweak and tune tools (rustup/cargo etc.) whenever required to smooth
sharp edges for RTEMS.

Here, I'm nearly finished with (1) for arm-rtems (e.g. cortex-aX not cortex-
mX).



Hi Karel,

Very interesting work. I am currently trying to reach the same goal.
The steps I came up with are a bit different:
A.) Build working llvm toolchain for RTEMS (figure out all flags etc., maybe 
building RTEMS with llvm as a bonus)
B.) Build rustc with the "RTEMS-llvm" as backend


Honestly I'm not so sure (A) and (B) are necessary for rustc port. Or 
perhaps I do not precisely follow what you mean, but IMHO what you need 
is to get ABI and linking with RTEMS binaries right. And this applies 
also to RTEMS being build by GCC toolchain. This is objective of my (1) 
work.



C.) Start with no_std and then inch forward to building the stdlib

I work currently on step A (see my llvm experiments in the other thread) and 
started to look at the build stages for rustc.
If you have any tips for the configuration from your step (1), it would be 
greatly appreciated.
My hope is that with the results of step A I can reuse the libc from the 
standard rtems-gcc build environment as this is provided conveniently via rsb.


Not sure if I did not confused you with my (2) libc remark. I of course 
mean Rust's libc (that means rust code) to be build on top of 
RTEMS/Newlib/libbsd combination. It'll be interesting project especially 
if the requirement later would be to support both binary targets: e.g. 
RTEMS without libbsd (for smaller systems) and RTEMS with libbsd for 
full-blown configuration. Anyway, for now, I would start with libbsd as 
this should make project proceeding faster IMHO.



I am really looking forward to seeing rust supported on RTEMS.


Me too!

Karel

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel