Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement libstd for CloudABI. #47268

Merged
merged 6 commits into from
Jan 14, 2018
Merged

Conversation

EdSchouten
Copy link
Contributor

Though CloudABI is strongly inspired by POSIX, its absence of features that don't work well with capability-based sandboxing makes it different enough that adding bits to sys/unix will make things a mess. This change therefore adds CloudABI specific platform code under sys/cloudabi.

One of the goals of this implementation is to build as much as possible directly on top of CloudABI's system call layer, as opposed to using the C library. This is preferred, as the system call layer is supposed to be stable, whereas the C library ABI technically is not. An advantage of this approach is that it allows us to implement certain interfaces, such as mutexes and condition variables more optimally. They can be lighter than the ones provided by pthreads.

This change disables some modules that cannot realistically be implemented right now. For example, libstd's pathname abstraction is not designed with POSIX *at() (e.g., openat()) in mind. The *at() functions are the only set of file system APIs available on CloudABI. There is no global file system namespace, nor a process working directory. Discussions on how to port these modules over are outside the scope of this change.

@rust-highfive
Copy link
Collaborator

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@EdSchouten EdSchouten force-pushed the cloudabi-libstd branch 2 times, most recently from 8ffc7be to 72aaa08 Compare January 8, 2018 11:43
@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 8, 2018
@EdSchouten EdSchouten force-pushed the cloudabi-libstd branch 2 times, most recently from adf24d1 to e7aa33c Compare January 8, 2018 14:12
@sfackler sfackler added I-needs-decision Issue: In need of a decision. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jan 8, 2018
@alexcrichton
Copy link
Member

Thanks for the PR @EdSchouten!

We discussed this PR at @rust-lang/libs triage today and we noted that one thing we'll probably want to do is keep the whole standard library compiling as-is on the cloudabi platform (e.g. continue to have std::net and such). We very much agree that it would be best to not have functionality compiled into libstd that forces a shim that always returns an error, but we're not quite ready to do this just yet. Notably we're missing an implementation of the portability lint and (as I'm sure you've discovered) the literal code organization of the standard library isn't currently amenable to cfg'ing out modules on some platforms and not others.

Along those lines could this take a wasm-like approach which implements the entire sys layer as expected by the standard library (withough cfg'ing off anything in the standard library) and simply returning errors from anything that the cloudabi platform doesn't implement? (this is what the wasm platform does). Eventually down the road we'll equip the standard library to remove these shims and actually delete all the always-returns-an-error code, but initially it'll be easier to not put cfg annotations in the standard library for that.

These automatically generated Rust source files allow us to invoke
system calls within CloudABI processes. These will be used by libstd to
implement primitives for I/O, threading, etc.

These source files are normally part of the 'cloudabi' crate. In the
case of libstd, we'd better copy them into the source tree, as having
external dependencies in libstd is a bit messy. Original source files
can be found here:

    https://github.com/NuxiNL/cloudabi/tree/master/rust
Though CloudABI is strongly inspired by POSIX, its absence of features
that don't work well with capability-based sandboxing makes it different
enough that adding bits to sys/unix will make things a mess. This change
therefore adds CloudABI specific platform code under sys/cloudabi and
borrows parts from sys/unix that can be used without changes.

One of the goals of this implementation is to build as much as possible
directly on top of CloudABI's system call layer, as opposed to using the
C library. This is preferred, as the system call layer is supposed to be
stable, whereas the C library ABI technically is not. An advantage of
this approach is that it allows us to implement certain interfaces, such
as mutexes and condition variables more optimally. They can be lighter
than the ones provided by pthreads.

This change disables some modules that cannot realistically be
implemented right now. For example, libstd's pathname abstraction is not
designed with POSIX *at() (e.g., openat()) in mind. The *at() functions
are the only set of file system APIs available on CloudABI. There is no
global file system namespace, nor a process working directory.
Discussions on how to port these modules over are outside the scope of
this change.

Apart from this change, there are still some other minor fixups that
need to be made to platform independent code to make things build. These
will be sent out separately, so they can be reviewed more thoroughly.
As discussed in rust-lang#47268, libstd isn't ready to have certain functionality
disabled yet. Follow wasm's approach of adding no-op modules for all of
the features that we can't implement.

I've placed all of those shims in a shims/ subdirectory, so we (the
CloudABI folks) can experiment with removing them more easily. It also
ensures that the code that does work doesn't get polluted with lots of
useless boilerplate code.
There are some tests that need to be disabled on CloudABI specifically,
due to the fact that the shims cannot be built in combination with
unix::ext or windows::ext. Also improve the scoping of some imports to
suppress compiler warnings.
Just like with wasm, we can't just import unix::ext and windows::ext.
Our shims are not complete enough for that.
@EdSchouten
Copy link
Contributor Author

Hi Alex,

Thanks to you and others for taking the time to discuss this! I have to say I only agree with this sentiment partially; I already had a set of patches that made a full ./x.py test && ./x.py dist pass that weren't a lot more complex than with shims in place. That said, I do understand that providing shims will make it easier to get started and puts less of a burden on the project.

I've just updated this pull request with three additional commits: one to put shims in place and two to make all of the tests/documentation build properly. Be sure to let me know what you think!

Ed

@EdSchouten
Copy link
Contributor Author

Hmmm... this is odd. Checks fail due to cfg(target_os = "cloudabi") being used in generic code, but those places already used target_os = "emscripten". What would be the preferred way of solving this?

@alexcrichton
Copy link
Member

Looks like there may be a specific exception for these lines but the modification is triggering it again?

@alexcrichton
Copy link
Member

(in that it should be fine to just tweak that exception logic)

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jan 11, 2018

📌 Commit 6a8d55a has been approved by alexcrichton

@alexcrichton alexcrichton added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed I-needs-decision Issue: In need of a decision. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 11, 2018
@EdSchouten
Copy link
Contributor Author

Sorry if I'm being impatient, but is this pull request actually in bors's queue? I'm seeing most pull requests getting merged by bors within one day, whereas this one is taking almost three days.

Just responding to this pull request to ensure it won't slip under the radar. There happened to be an outage on GitHub around the time this got approved. Maybe this interfered with it being queued?

@bors
Copy link
Contributor

bors commented Jan 14, 2018

⌛ Testing commit 6a8d55a with merge 48ab4cd...

bors added a commit that referenced this pull request Jan 14, 2018
Implement libstd for CloudABI.

Though CloudABI is strongly inspired by POSIX, its absence of features that don't work well with capability-based sandboxing makes it different enough that adding bits to `sys/unix` will make things a mess. This change therefore adds CloudABI specific platform code under `sys/cloudabi`.

One of the goals of this implementation is to build as much as possible directly on top of CloudABI's system call layer, as opposed to using the C library. This is preferred, as the system call layer is supposed to be stable, whereas the C library ABI technically is not. An advantage of this approach is that it allows us to implement certain interfaces, such as mutexes and condition variables more optimally. They can be lighter than the ones provided by pthreads.

This change disables some modules that cannot realistically be implemented right now. For example, libstd's pathname abstraction is not designed with POSIX `*at()` (e.g., `openat()`) in mind. The `*at()` functions are the only set of file system APIs available on CloudABI. There is no global file system namespace, nor a process working directory. Discussions on how to port these modules over are outside the scope of this change.
@petrochenkov
Copy link
Contributor

@EdSchouten

is this pull request actually in bors's queue? I'm seeing most pull requests getting merged by bors within one day, whereas this one is taking almost three days.

You can see the queue here - https://buildbot2.rust-lang.org/homu/queue/rust.
Pull requests are merged in order from oldest to newest (unless manually prioritized or rolled up).
Time until merge can vary a lot depending on several factors, so waiting for several days is not unusual.

@EdSchouten
Copy link
Contributor Author

Hey @petrochenkov. Thanks for the link. That's pretty useful!

@bors
Copy link
Contributor

bors commented Jan 14, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 48ab4cd to master...

@bors bors merged commit 6a8d55a into rust-lang:master Jan 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants