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

std no longer compiles for riscv32imc-esp-espidf #95924

Closed
bugadani opened this issue Apr 11, 2022 · 5 comments
Closed

std no longer compiles for riscv32imc-esp-espidf #95924

bugadani opened this issue Apr 11, 2022 · 5 comments

Comments

@bugadani
Copy link
Contributor

I'm trying to cross-copmile for an espidf target from Windows, but in the latest nightly compilation (or in this case, cargo c) fails with the following errors:

cargo c --target=riscv32imc-esp-espidf -Z build-std=std,panic_abort

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\os\unix\process.rs:166:33
    |
166 |         self.as_inner_mut().uid(id);
    |                                 ^^ expected `u16`, found `u32`
    |
help: you can convert a `u32` to a `u16` and panic if the converted value doesn't fit
    |
166 |         self.as_inner_mut().uid(id.try_into().unwrap());
    |                                   ++++++++++++++++++++

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\os\unix\process.rs:175:33
    |
175 |         self.as_inner_mut().gid(id);
    |                                 ^^ expected `u16`, found `u32`
    |
help: you can convert a `u32` to a `u16` and panic if the converted value doesn't fit
    |
175 |         self.as_inner_mut().gid(id.try_into().unwrap());
    |                                   ++++++++++++++++++++

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\os\unix\process.rs:184:36
    |
184 |         self.as_inner_mut().groups(groups);
    |                                    ^^^^^^ expected `u16`, found `u32`
    |
    = note: expected reference `&[u16]`
               found reference `&[u32]`

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\unix\fd.rs:112:17
    |
112 |                 offset as i64,
    |                 ^^^^^^^^^^^^^ expected `i32`, found `i64`
    |
help: you can convert an `i64` to an `i32` and panic if the converted value doesn't fit
    |
112 |                 (offset as i64).try_into().unwrap(),
    |                 +             +++++++++++++++++++++

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\unix\fd.rs:179:17
    |
179 |                 offset as i64,
    |                 ^^^^^^^^^^^^^ expected `i32`, found `i64`
    |
help: you can convert an `i64` to an `i32` and panic if the converted value doesn't fit
    |
179 |                 (offset as i64).try_into().unwrap(),
    |                 +             +++++++++++++++++++++

error[E0308]: mismatched types
   --> C:\Users\bugad\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\unix\fs.rs:969:56
    |
969 |         let n = cvt(unsafe { lseek64(self.as_raw_fd(), pos, whence) })?;
    |                                                        ^^^ expected `i32`, found `i64`
    |
help: you can convert an `i64` to an `i32` and panic if the converted value doesn't fit
    |
969 |         let n = cvt(unsafe { lseek64(self.as_raw_fd(), pos.try_into().unwrap(), whence) })?;
    |                                                           ++++++++++++++++++++
@bugadani
Copy link
Contributor Author

bugadani commented Apr 11, 2022

I haven't tried bisecting it, I can only confirm that the same project compiles fine with nightly-2022-04-01

@RangerDevv
Copy link

I have had the same issue. Idk how to solve it though. :(

@gyscos
Copy link

gyscos commented Apr 12, 2022

Looking at the first error: a uid() function is called with a u32, but it expected a u16.

The function is called here:
https://github.com/rust-lang/rust/blob/master/library/std/src/os/unix/process.rs#L166
Here the argument (we know it's a u32 from the error message) depends on the target_os; it's u16 for vxworks, and u32 for everything else.

The function is defined here:
https://github.com/rust-lang/rust/blob/master/library/std/src/sys/unix/process/process_common.rs#L199
The argument type is libc::uid_t.

That type is defined here:
https://github.com/rust-lang/libc/blob/f0f4b689906862bf74297042022c20ada7274b71/src/unix/mod.rs#L33
It's a c_ushort (u16) on the espidf target OS.

So at least we understand the issue. Now - why was it working before? Did any of these definitions change recently? None of the files linked here have recent relevant commits that could have changed that. Maybe the libc version was updated recently?
Libc updated the uid_t definition on March 12nd: rust-lang/libc@ab62380#diff-a828924ffbc30c564e49bc3652ffa5375a123671b228fc99b5775a29cff6eea5R27 from the PR rust-lang/libc#2708

A fix could be to use libc::uid_t as parameter type in CommandExt::uid, rather than u32 for all non-vxworks platform? Or if we don't want to expose libc here, re-export just its uid_t type, or re-implement the type definition?

The same thing happened with libc::gid_t.

Then, probably the same with off_t from libc, which was i64 before and is now c_long on espidf (which is i32)

Ah looks like the fix is in the works:
#94609

@ivmarkov
Copy link
Contributor

Will be fixed once this is merged: #94609

@bugadani
Copy link
Contributor Author

Thanks, this has been fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants