-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix building libstd on emscripten targets. #31986
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
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This is the error I was getting before the changes:
|
I'm believe libstd used to build fine with emscripten targets, but I think this commit broke it: aa23c98 These new fs metadata functions as defined in |
#[allow(deprecated)] | ||
use os::emscripten::raw; | ||
|
||
#[cfg(not(target_os = "emscripten"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That could be replaced with just use super::raw;
.
The |
tv_sec: self.stat.st_atime as libc::time_t, | ||
tv_nsec: self.stat.st_atime_nsec as libc::c_long, | ||
})) | ||
#[cfg(any(target_env = "musl", target_os = "emscripten"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these additions of musl
may not be necessary because the standard library is already guaranteed to compile for x86_64-unknown-linux-musl
Ok, thanks for the tips. I reverted all the changes in I also made some changes in the EDIT: Is it reasonable to assume that when compiling for |
} | ||
|
||
pub fn accessed(&self) -> io::Result<SystemTime> { | ||
Ok(SystemTime::from(libc::timespec { | ||
tv_sec: self.stat.st_atime as libc::time_t, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this call self.st_atime()
and self.st_atime_nsec()
? I think that would help remove the #[cfg]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a look at doing that, but I don't think it is possible.
st_atime()
and st_atime_sec()
are functions available only on structs that implement libstd::os::emscripted::fs::MetedataExt or libstd::sys::unix::ext::fs::MetadataExt but I believe the FileAttr struct doesn't implement either of those traits.
In this case the FileAttr struct only has access to its own inner stat: stat64
struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right.
In the interest of consistency with other platforms, I think the best solution here would actually be to just modify the libc bindings themselves. Anyone using them manually will require these #[cfg]
directives anyway, so we may as well get them all aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you elaborate on what you mean here?
Are you saying to change liblibc so that it uses the definitions in unix/notbsd/linux/other/b32
rather than unix/notbsd/linux/musl/b32/asmjs
for emscripten targets?
Im not sure if it will be as easy as that, but I can try it out to see how it works.
If we do that, and it works, then most of the changes in this PR will not be required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah for all other platforms we store the two fields in st_atim
differently, one for the seconds and one for the nanoseconds. Looks like we accidentally used timeval
here and we should just switch to two separate fields like in other platofrms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think it was an accident. It was most likely copied from here:
https://github.com/kripken/emscripten/blob/incoming/system/lib/libc/musl/arch/emscripten/bits/stat.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but to mirror how other platforms work and avoid this #[cfg]
we expand the struct to an equivalent set of individual fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I get it. Yes, I see it the struct will still be byte-compatible and equivalent with individual fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think it's actually getting taken care of in rust-lang/libc#210, once that's merged this can probably just update libc again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I saw the change was merged, so I targeted libc to that commit, and undone these lines.
Should I squash all these commits together? |
Updated to liblibc e19309c, then took out the extra compile-time cfg checks for emscripten in the FileAttr struct impl. Also rebased to current master, and rebuilt locally and ran all my compilation and usability tests. |
Thanks! Could you also squash the commits down together as well? |
@@ -156,7 +160,7 @@ impl FileAttr { | |||
} | |||
|
|||
pub fn accessed(&self) -> io::Result<SystemTime> { | |||
Ok(SystemTime::from(libc::timespec { | |||
return Ok(SystemTime::from(libc::timespec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change can probably be left out for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that was an accident. Shouldn't have been in the commit.
Squashed 10 commits: 1) The main cause of the problem is that libstd/os/mod.rs treats emscripten targets as an alias of linux targets, whereas liblibc treats emscripten targets as musl-compliant, so it gets a slightly different struct stat64 defined. This commit adds conditional compilation checks to use the correct timestamp format on fs metadata functions in the case of compiling to emscripten targets. 2) Update previous commit to comply with rust formatting standards. Removed tab characters, remove trailing whitespaces. 3) Move emscripten changes into their own file under libstd/os/emscripten Put libstd/os/linux/fs back to the way it was. 4) Cannot use stat.st_ctim on emscripten to get created time. 5) Remove compile-time conditionals for target_env = musl, it looks like musl builds compile fine already. 6) Undone some formatting changes that are no longer needed, Removed some more target_env="musl" compilation checks that I missed from my previous commit. 7) upgrade to liblibc e19309c, it fixes the differences in the musl stat and stat64 definitions. 8) Undo the compile-time checks to check for emscripten (or musl targets) in the FileAttr struct. No longer needed after updating liblibc to e19309c. 9) Change the MetadataExt implementation of emscripten fs.rs module to match the changes in new liblibc. 10) remove a stray return statement, should have been removed in the previous commit.
⌛ Testing commit 660bbf4 with merge d5d838b... |
💔 Test failed - auto-win-gnu-64-nopt-t |
@bors: retry On Mon, Mar 7, 2016 at 5:46 AM, bors [email protected] wrote:
|
The main cause of the problem is that libstd/os/mod.rs treats emscripten targets as an alias of linux targets, whereas liblibc treats emscripten targets as musl-compliant, so it gets a slightly different struct stat64 defined. This commit adds conditional compilation checks to use the correct timestamp format on fs metadata functions in the case of compiling to emscripten targets. This commit also depends needs https://github.com/ashleysommer/rust/commit/f1575cff2d631e977038fdba3fa3422ba5f8f2fe applied in order to successfully build libstd with emscripten target.
@bors: retry force |
Fix building libstd on emscripten targets. The main cause of the problem is that libstd/os/mod.rs treats emscripten targets as an alias of linux targets, whereas liblibc treats emscripten targets as musl-compliant, so it gets a slightly different struct stat64 defined. This commit adds conditional compilation checks to use the correct timestamp format on fs metadata functions in the case of compiling to emscripten targets. This commit also depends needs https://github.com/ashleysommer/rust/commit/f1575cff2d631e977038fdba3fa3422ba5f8f2fe applied in order to successfully build libstd with emscripten target.
…crichton The main cause of the problem is that libstd/os/mod.rs treats emscripten targets as an alias of linux targets, whereas liblibc treats emscripten targets as musl-compliant, so it gets a slightly different struct stat64 defined. This commit adds conditional compilation checks to use the correct timestamp format on fs metadata functions in the case of compiling to emscripten targets. This commit also depends needs https://github.com/ashleysommer/rust/commit/f1575cff2d631e977038fdba3fa3422ba5f8f2fe applied in order to successfully build libstd with emscripten target.
The main cause of the problem is that libstd/os/mod.rs treats emscripten targets as an alias of linux targets, whereas liblibc treats emscripten targets as musl-compliant, so it gets a slightly different struct stat64 defined.
This commit adds conditional compilation checks to use the correct timestamp format on fs metadata functions in the case of compiling to emscripten targets.
This commit also depends needs https://github.com/ashleysommer/rust/commit/f1575cff2d631e977038fdba3fa3422ba5f8f2fe applied in order to successfully build libstd with emscripten target.