Skip to content

nuttx: clean up module#5245

Open
dybucc wants to merge 5 commits into
rust-lang:mainfrom
dybucc:nuttx-cleanup
Open

nuttx: clean up module#5245
dybucc wants to merge 5 commits into
rust-lang:mainfrom
dybucc:nuttx-cleanup

Conversation

@dybucc

@dybucc dybucc commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Description

This PR consists of an overall clean up of the NuttX module. It adds missing types, fixes one type definition, replaces equivalent with mirrored definitions (fixed-width types with "variable" C types,) and provides correct support for some build-time configuration options.

The build-time configuration options correspond with CONFIG_SMALL_MEMORY and CONFIG_FS_LARGEFILE. The former enables types with pointer bit width (size_t and ssize_t) to be narrower than required in the target. It is enabled by default in 16-bit machine word targets but can also be enabled in other targets. The latter option enables support for LFS bindings. The default under all targets is to expose 32-bit types and no suffixed 64-bit types. It is only if the above option is set that (1) suffixed types are exposed and (2) unsuffixed types are made 64-bits wide. I have decided against exposing the suffixed types because it's redundant.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget); especially relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Jul 3, 2026
Comment thread src/unix/nuttx/mod.rs Outdated
};

pub type id_t = c_int;
pub type key_t = u32;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: add missing types": Isn't this signed? https://github.com/apache/nuttx/blob/9e467388de0285c1c160681aeafaa9c6b5723ac0/include/sys/types.h#L170

Make sure your links to source are permalinks (available under the triple dots) so we know what things looked like if they change in the future.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done. noted.

Comment thread src/unix/nuttx/mod.rs
pub type dev_t = i32;
pub type fsblkcnt_t = u64;
pub type loff_t = off_t;
pub type cpu_set_t = u32;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: add missing types": Is this definition used? I'd prefer to omit it because of the volatile

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it seems like it is upstream 1. we don't provide any bindings to routines that use it, though.

Footnotes

  1. https://github.com/search?q=repo%3Aapache%2Fnuttx+path%3A**%2F*.h+%2F%5Cbcpu_set_t%5Cb%2F&type=code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, avoid adding things without a specific usecase. If somebody needs it and adds it that's fine, but if not then it's kind of opting us into maintenance effort for something that might not even be used.

This also isn't a correct definition anyway, it's volatile.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. For now, it's best to add things on an as‑needed basis, since the definitions on the NuttX side may change (e.g., ino_t). Don't introduce unused definitions too early.

Comment thread src/unix/nuttx/mod.rs Outdated
pub type socklen_t = u32;
pub type speed_t = usize;
pub type suseconds_t = i32;
pub type useconds_t = i32;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right. done.

Comment thread src/unix/nuttx/mod.rs
pub type tcflag_t = u32;
pub type clockid_t = i32;
pub type time_t = i64;
pub type timer_t = *mut c_void;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eek far pointers in the definition. Is this actually needed?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not in our bindings. it is used upstream 1.

what is it with far pointers? is it inconvenient to test against them because of the segment:offset divide, or is there something else?

Footnotes

  1. https://github.com/search?q=repo%3Aapache%2Fnuttx+path%3A**%2F*.h+%2F%5Cbtimer_t%5Cb%2F&type=code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is it with far pointers? is it inconvenient to test against them because of the segment:offset divide, or is there something else?

Rust just doesn't support them at all because LLVM support is still in the works, as far as I know.

It looks like this is only relevant on AVR https://github.com/apache/nuttx/blob/cce73da215469a7709cd5ffec5d0ad8d8c98309e/include/nuttx/compiler.h#L471-L545 (though I didn't scan end-to-end) so the definition is technically ok, though same as #5245 (comment) we should avoid adding API with no consumer.

Comment thread src/unix/nuttx/mod.rs
pub type key_t = u32;
pub type nlink_t = u16;
pub type ino_t = u16;
pub type ino_t = u32;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: fix ino_t definition" this happened just last week apache/nuttx@50377d0, I have no clue what the release/support schedule looks like but we should probably hold off a bit. Or at least hear from the maintainers.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just pinged the maintainers.

Comment thread src/unix/nuttx/mod.rs Outdated
Comment on lines +39 to +40
pub type wchar_t = i32;
pub type wchar_t = c_int;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: mirror type definitions" Seems fine but where does this one come from?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

pre-defined compiler macros. it's defined as __wchar_type__ 1, which at least in clang expands to a c int under riscv and to a c unsigned int under arm (both 32- and 64-bit) 2. supported rust targets are under either one of these isas.

just made it conditionally compiled when i realized the compiler definitions were different under these two architectures.

Footnotes

  1. https://github.com/search?q=repo%3Aapache%2Fnuttx+%2F%5Cb_wchar_t%5Cb%2F&type=code

  2. https://c.godbolt.org/z/czMY79vsh

Comment thread src/unix/nuttx/mod.rs
pub type locale_t = *mut i8;
pub type mode_t = u32;
pub type nfds_t = u32;
pub type off_t = i64;

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: provide correct lfs support": It looks like we were already supporting CONFIG_FS_LARGEFILE - why the change?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we were not correctly supporting that configuration. without it enabled, all targets get 32-bit file offset types. with it enabled, they all get 64-bit file offset types.

it would likely come off as a surprise if somebody didn't have CONFIG_FS_LARGEFILE enabled but found that our types are 64-bits either way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean we were only supporting CONFIG_FS_LARGEFILE, right? That's completely fine, every platform has dozens of ways you could configure it that make something break for Rust.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I mean we were only supporting CONFIG_FS_LARGEFILE, right? That's completely fine, every platform has dozens of ways you could configure it that make something break for Rust.

Yes, it is unlikely to support arbitrary configurations of the NuttX ABI on the Rust side, so we must restrict the configuration options that affect fundamental data type definitions and only support the most commonly used combinations.

Comment thread src/unix/nuttx/mod.rs Outdated
}

cfg_if! {
if #[cfg(nuttx_small_mm)] {

@tgross35 tgross35 Jul 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"nuttx: expose cfg for small memory model" similarly, I don't think there is any need to add this - it's extra configuration complexity in libc and has no known users. This would probably have to be a separate target in rustc, anyway.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed.

dybucc added 5 commits July 7, 2026 15:59
fix signedness of wchar_t under arm and aarch64. this was not correctly
handled as this type will likely be defined in terms of predefined
compiler macros [^1]. these macros expand to different types on our
currently supported nuttx targets. they are only signed integers under
riscv [^2].

[^1]: https://github.com/search?q=repo%3Aapache%2Fnuttx+%2F%5Cb_wchar_t%5Cb%2F&type=code
[^2]: https://c.godbolt.org/z/czMY79vsh
Use `gnu_file_offset_bits64` `cfg` to export LFS bindings. NuttX follows
that "64"-suffixed symbols are exposed only if large file support is
enabled [^1] [^2]. We choose not to expose those because it's redundant.
Otherwise, the existing `cfg` serves the same purpose as upstream's
`CONFIG_FS_LARGEFILE` build option.

[^1]: https://github.com/apache/nuttx/blob/master/include/sys/types.h#L88-L95
[^2]: https://github.com/apache/nuttx/blob/master/include/sys/types.h#L199-L226
@rustbot

rustbot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@dybucc

dybucc commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@no1wudi, you think we can already have an ino_t definition that matches upstream? there was a recent change there and this pr includes it, but maybe that's a bit too early to make changes.

@rustbot ready

Comment thread src/unix/nuttx/mod.rs
// types are themselves 64-bits wide. We choose to expose ony the latter.
cfg_if! {
if #[cfg(gnu_file_offset_bits64)] {
pub type fsblkcnt_t = u64;

@no1wudi no1wudi Jul 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are too many configuration options inside Nuttx; it would be better to only support specific projects. For example, FS_LARGEFS must be enabled; otherwise, compilation becomes overly difficult.

View changes since the review

Comment thread src/unix/nuttx/mod.rs
pub type dev_t = i32;
pub type fsblkcnt_t = u64;
pub type loff_t = off_t;
pub type cpu_set_t = u32;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed. For now, it's best to add things on an as‑needed basis, since the definitions on the NuttX side may change (e.g., ino_t). Don't introduce unused definitions too early.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants