Skip to content
This repository was archived by the owner on Oct 29, 2026. It is now read-only.

Split up some files into modules/impl FS functions - #104

Merged
sunfishcode merged 28 commits into
sunfishcode:mainfrom
carbotaniuman:work
Apr 25, 2022
Merged

sunfishcode merged 28 commits into
sunfishcode:mainfrom
carbotaniuman:work

Conversation

@carbotaniuman

@carbotaniuman carbotaniuman commented Mar 25, 2022 •

Copy link
Copy Markdown
Contributor

The main point of this change is to make sure all LFS functions are implemented in terms of the the 64 variant, as well as move all of the fs located code outside of the single massive file. Where functions ending in at were missing, they have been added and all calls updated to reduce code duplication.

Closes (because that's probably better than putting a comment in each issue): #88, partial #87, #71.

@sunfishcode

Copy link
Copy Markdown
Owner

Cool! I'll take a closer look in a few days, but I wanted to quickly check in here and say this looks like a great place to start.

Also, there's a possibility that splitting lib.rs into multiple files will lead to undefined symbols at link time; if that happens, one option is to use include! to link the individual files into lib.rs instead of mod.

@carbotaniuman carbotaniuman mentioned this pull request Mar 30, 2022
@sunfishcode

Copy link
Copy Markdown
Owner

At a first readthrough, this looks like a good direction. I'll be interested to see what happens when the current CI failures are fixed (rustfmt, and there are likely some conversions needed when dealing with libc::stat fields), and we can see what happens at link time.

@carbotaniuman

Copy link
Copy Markdown
Contributor Author

I think you need to punch the button, as the CI hasn't been running for several commits. This seems like a good point to see how far I get in the CI anyways.

@carbotaniuman

Copy link
Copy Markdown
Contributor Author

Ok I've finally gotten to the linking errors. How is c-scape built (aka what crate-type), and how/where is it linked in?

@sunfishcode

Copy link
Copy Markdown
Owner

Currently, the way it works is:

The tricky part of this setup seems to be that some of the extern-C symbols get dropped before we reach the final link, when the linker realizes they're actually needed.

Putting all the code in a single lib.rs file seems to avoid this problem, though I don't yet know why it works. include!, as opposed to mod would be a way to achieve that, while still having the code in separate files.

I'm also open to other approaches here. "Put everything in lib.rs" is the only thing I've found that works, but if there's a better way to do it, I'm certainly open to it.

@carbotaniuman

Copy link
Copy Markdown
Contributor Author

Ok I've solved it with:

[profile.dev.package.c-scape]
codegen-units = 1

[profile.test.package.c-scape]
codegen-units = 1

I'm working on some rustc fixes in this space, but for now that's probably the best workaround for us. I'll take a look at the linking in more depth later.

@sunfishcode sunfishcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, thanks for figuring out the codegen-units fix. That'll make it much easier to organize this code.

Comment thread Cargo.toml Resolved
Comment thread Cargo.toml Resolved
Comment thread c-scape/src/process/kill.rs Outdated
n if n < 0 => {
rustix::process::kill_process_group(Pid::from_raw(pid.unsigned_abs()).unwrap(), sig)
}
_ => unreachable!(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unreachable! could be avoided by making what is currently the 0 case be the default case after the n < 0 and n > 0 cases.

Comment thread c-scape/src/fs/lseek.rs Resolved
Comment thread c-scape/src/fs/open.rs Resolved
Comment thread c-scape/src/fs/stat.rs Resolved
Comment thread c-scape/src/process/chdir.rs Resolved
@sunfishcode

Copy link
Copy Markdown
Owner

This is currently marked as a draft; is this ready for review?

@sunfishcode
sunfishcode force-pushed the work branch 2 times, most recently from 39d0683 to 341a05e Compare April 12, 2022 00:56
@carbotaniuman

Copy link
Copy Markdown
Contributor Author

I think this is ready for review now, but I do need to figure out how to add tests for every function that I added though.

@sunfishcode sunfishcode left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! It'll be much nicer having everything factored out into modules like this.

Concerning tests for new functions, my sense is that it's not necessary to have tests for every function at this point. A complete c-scape testsuite would effectively be a libc or POSIX testsuite, and there are already a number of such testsuites out there that we could potentially use, for example musl's. I expect we'll eventually wire some of these up, which will provide a lot more test coverage.

Comment thread c-scape/src/io/epoll.rs Resolved
Comment thread c-scape/src/io/mod.rs Resolved
Comment thread c-scape/src/io/isatty.rs Resolved
Comment thread c-scape/src/fs/realpath.rs Resolved
@carbotaniuman

Copy link
Copy Markdown
Contributor Author

Build won't be green for a while until rustix gets updated, as I'm knocking out termios right now. a39ec76 should be reviewable however, so these changes can simply just be split into a seperate PR.

@sunfishcode

Copy link
Copy Markdown
Owner

Would you mind opening a new PR for the termios and any other changes? I'd like to land the main changes here, so that we can build on top of the new code organization.

@carbotaniuman

Copy link
Copy Markdown
Contributor Author

Yeah I just did, I realized after a short nap that I could just... use another branch.

@sunfishcode
sunfishcode marked this pull request as ready for review April 25, 2022 16:26
@sunfishcode

Copy link
Copy Markdown
Owner

This new organization looks great!

@sunfishcode
sunfishcode merged commit be0cb59 into sunfishcode:main Apr 25, 2022
@carbotaniuman
carbotaniuman deleted the work branch April 25, 2022 16:54
This was referenced Jun 23, 2022
@sunfishcode sunfishcode mentioned this pull request Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants