Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix building libstd on emscripten targets. #31986
Conversation
rust-highfive
assigned
brson
Mar 1, 2016
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This is the error I was getting before the changes:
|
This comment has been minimized.
This comment has been minimized.
|
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 |
tomaka
reviewed
Mar 1, 2016
| #[allow(deprecated)] | ||
| use os::emscripten::raw; | ||
|
|
||
| #[cfg(not(target_os = "emscripten"))] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The |
alexcrichton
reviewed
Mar 1, 2016
| 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"))] |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 1, 2016
Member
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
alexcrichton
reviewed
Mar 1, 2016
| tv_nsec: self.stat.st_birthtime_nsec as libc::c_long, | ||
| })) | ||
| #[cfg(any(target_os = "emscripten"))] | ||
| { return Ok(SystemTime::from( self.stat.st_ctim )); } |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 1, 2016
Member
I think that ctim isn't the created time but rather the time of the last status change.
This comment has been minimized.
This comment has been minimized.
|
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 |
alexcrichton
reviewed
Mar 2, 2016
| } | ||
|
|
||
| pub fn accessed(&self) -> io::Result<SystemTime> { | ||
| Ok(SystemTime::from(libc::timespec { | ||
| tv_sec: self.stat.st_atime as libc::time_t, |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 2, 2016
Member
Could this call self.st_atime() and self.st_atime_nsec()? I think that would help remove the #[cfg]
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 2, 2016
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 2, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 2, 2016
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 3, 2016
Member
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.
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 3, 2016
Author
Contributor
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
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 3, 2016
Member
Yeah, but to mirror how other platforms work and avoid this #[cfg] we expand the struct to an equivalent set of individual fields.
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 4, 2016
Author
Contributor
Oh I get it. Yes, I see it the struct will still be byte-compatible and equivalent with individual fields.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 6, 2016
Member
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
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 7, 2016
Author
Contributor
Ok, I saw the change was merged, so I targeted libc to that commit, and undone these lines.
alexcrichton
reviewed
Mar 2, 2016
| @@ -174,7 +191,8 @@ impl FileAttr { | |||
|
|
|||
| #[cfg(not(any(target_os = "bitrig", | |||
| target_os = "freebsd", | |||
| target_os = "openbsd")))] | |||
| target_os = "openbsd" | |||
| )))] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
Mar 2, 2016
| @@ -25,15 +25,21 @@ use sys::time::SystemTime; | |||
| use sys::{cvt, cvt_r}; | |||
| use sys_common::{AsInner, FromInner}; | |||
|
|
|||
| #[cfg(target_os = "linux")] | |||
| #[cfg(any(target_os = "linux", target_env = "musl", target_os = "emscripten"))] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Mar 2, 2016
Member
Because MUSL implies target_os = "linux" I think that clause can be removed from this and the bits below
This comment has been minimized.
This comment has been minimized.
|
Should I squash all these commits together? |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
Thanks! Could you also squash the commits down together as well? |
alexcrichton
reviewed
Mar 7, 2016
| @@ -156,7 +160,7 @@ impl FileAttr { | |||
| } | |||
|
|
|||
| pub fn accessed(&self) -> io::Result<SystemTime> { | |||
| Ok(SystemTime::from(libc::timespec { | |||
| return Ok(SystemTime::from(libc::timespec { | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ashleysommer
Mar 7, 2016
Author
Contributor
Yep, that was an accident. Shouldn't have been in the commit.
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 7, 2016
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
@bors: retry On Mon, Mar 7, 2016 at 5:46 AM, bors notifications@github.com wrote:
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Mar 7, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors: retry force |
ashleysommer commentedMar 1, 2016
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.