sunfishcode / mustang

Rust programs written entirely in Rust
Other
827 stars 24 forks source link

Why is the target gnu? #218

Closed morr0ne closed 1 year ago

morr0ne commented 1 year ago

I'm trying to get a better understanding of how this library works. If I'm not mistaken it's trying to implement the subset of C calls required to compile rust programs. If that's the case why are the target x86_64-mustang-linux-gnu? Wouldn't it make more sense to drop the gnu (e.g. x86_64-mustang-linux) or replace it with mustang (e.g. x86_64-unknown-linux-mustang)? Maybe I'm misunderstanding where this library is placed but I'm failing to understand the approach. Perhaps I don't have a good enough understanding of how rust work but wouldn't it make more sense to modify the existing std implementation to use rust directly instead of rewriting the C calls in rust?

sunfishcode commented 1 year ago

x86_64-mustang-linux-gnu works by implementing the x86_64-unknown-linux-gnu ABI. That allows it to slide underneath std and also other libc-using code compiled to the x86_64-unknown-linux-gnu ABI without any modifications. And in addition to Rust code, it can also support C code, such as libgit2, which some popular Rust crates use.

Mustang is structured such that all the major functionality is implemented with a Rust-idiomatic API first, and a discrete C ABI compatibility layer on top, in theory to enable things like std using the lower-level Rust APIs directly. I've done some experimenting with porting std to use Rust directly, and it can be done. That said, I've not been very active with mustang for some time. I guess it's "waiting for a sign".

morr0ne commented 1 year ago

What would be required to port std to only use rust? Can it just be implemented as a new target or would it need to change some of the code to not us C? I was thinking about it for a long and I was very close to fork rust and start working on it when I saw mustang. I guess it's not really what I've been looking for but it's a good starting point. Is there already some prior work on porting std to rust instead of starting fresh?

That said, I've not been very active with mustang for some time. I guess it's "waiting for a sign".

What kind of sign would that be?

sunfishcode commented 1 year ago

What would be required to port std to only use rust? Can it just be implemented as a new target or would it need to change some of the code to not us C? I was thinking about it for a long and I was very close to fork rust and start working on it when I saw mustang. I guess it's not really what I've been looking for but it's a good starting point. Is there already some prior work on porting std to rust instead of starting fresh?

There are multiple possible paths. Mustang today can already run many real-world Rust programs using only Rust code. It does so by taking std as-is and replacing the libc it's compiled to use with an ABI-compatible library written in Rust.

Alternatively, it should be possible to modify std to use the underlying Rust libraries rustix and origin directly, either by changing the existing unix implementation code, or by creating a new target. This would have the advantage of avoiding some inefficiencies of the C ABI.

This is a fork of Rust where I started doing that. It's not very complete, and it's out of date at this point, so perhaps it makes sense to start new efforts from scratch rather than taking that actual branch, but it may provide some inspiration.

That said, I've not been very active with mustang for some time. I guess it's "waiting for a sign".

What kind of sign would that be?

I don't know. For this project to make sense, it has to have a bigger picture than just me pushing it forward because I think it's fun. I don't know exactly what that looks like, or how to go about making it happen, so I'm waiting to see what might emerge.

morr0ne commented 1 year ago

Alternatively, it should be possible to modify std to use the underlying Rust libraries rustix and origin directly, either by changing the existing unix implementation code, or by creating a new target. This would have the advantage of avoiding some inefficiencies of the C ABI.

Well that is pretty much what I had in mind, I'm gonna try adding a new target using rustix. Not sure what the name should be and I def need to read up on the rust contribution guidelines but that's a good starting point. Maybe it would make sense to separate origin into another repo? I understand it was made with mustang in mind but I feel like it would benefit from being a separate project

This is a fork of Rust where I started doing that. It's not very complete, and it's out of date at this point, so perhaps it makes sense to start new efforts from scratch rather than taking that actual branch, but it may provide some inspiration.

I'll take a look at it but it's prob better to start fresh considering that fork is 61730 commits behind

I don't know. For this project to make sense, it has to have a bigger picture than just me pushing it forward because I think it's fun. I don't know exactly what that looks like, or how to go about making it happen, so I'm waiting to see what might emerge.

Would it make sense to add some kind of notice/disclaimer about the status of this project?

sunfishcode commented 1 year ago

Sounds good! I posted https://github.com/sunfishcode/mustang/pull/219 to move origin to its own repo.

Would it make sense to add some kind of notice/disclaimer about the status of this project?

I myself don't know what it should say. The project does what it says on the tin, it's maintained, and I'm happy to answer questions, and to help out where I can.

morr0ne commented 1 year ago

Sounds good! I posted https://github.com/sunfishcode/mustang/pull/219 to move origin to its own repo.

Well that was fast, any reason to not just merge the pr?

I myself don't know what it should say. The project does what it says on the tin, it's maintained, and I'm happy to answer questions, and to help out where I can.

I guess I misunderstood a little, as long as its maintained I do not think any notice is necessary, considering the fast response I am getting (thank for that btw) it's way more maintained that other projects

On another note, I did just fork rust in the hope of adding a non C target. I am struggling a bit tho, is there some prior discussion or place when one might continue this conversation?

sunfishcode commented 1 year ago

Sounds good! I posted #219 to move origin to its own repo.

Well that was fast, any reason to not just merge the pr?

I've now merged it.

On another note, I did just fork rust in the hope of adding a non C target. I am struggling a bit tho, is there some prior discussion or place when one might continue this conversation?

I'm not aware of any prior discussions.

sunfishcode commented 1 year ago

If there are any further questions here, please file new issues!