Skip to content

Enable libc-test and fix definitions/declarations for AIX #4450

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

xingxue-ibm
Copy link
Contributor

@xingxue-ibm xingxue-ibm commented May 9, 2025

Description

This PR enables libc-test on AIX. With the fixes to definitions and declarations, libc-test now runs successfully on AIX.

Sources

Checklist

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

@xingxue-ibm xingxue-ibm force-pushed the enable-aix-libc-test branch 5 times, most recently from 0a7ad40 to 6c81afa Compare May 9, 2025 19:08
@xingxue-ibm xingxue-ibm marked this pull request as ready for review May 9, 2025 19:33
Comment on lines 72 to 80
#[cfg(target_os = "aix")]
if cmsg_len % std::mem::size_of::<cmsghdr>() != 0 {
continue;
}
for next_cmsg_len in 0..32 {
// The size of socklen_t is 4-bytes on AIX.
#[cfg(target_os = "aix")]
let cmsg_len2: u32 = cmsg_len as u32;
#[cfg(not(target_os = "aix"))]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could if cfg!(...) be used instead of #[cfg(...)] so the test still gets type checked on other platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment! I tried the following:

(*pcmsghdr).cmsg_len = if cfg!(target_os = "aix") {
    cmsg_len as u32
} else {
    cmsg_len
};

but got this error:

  --> libc-test/test/cmsg.rs:83:29
   |
83 | ...                   cmsg_len
   |                       ^^^^^^^^ expected `u32`, found `usize`
   |
help: you can convert a `usize` to a `u32` and panic if the converted value doesn't fit
   |
83 |                             cmsg_len.try_into().unwrap()
   |                                     ++++++++++++++++++++

Changing as the compiler suggests does work:

                        (*pcmsghdr).cmsg_len = if cfg!(target_os = "aix") {
                            cmsg_len as u32
                        } else {
                            cmsg_len.try_into().unwrap()
                        };

But this does not seem to check the type on other platforms either. Any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I didn't realize they are different types. Could you just do (*pcmsghdr).cmsg_len = cmsg_len as _?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea! It works perfectly, thanks so much, @tgross35!

@tgross35
Copy link
Contributor

One minor nit from me. I don't see anything concerning, but also don't know the platform so I'll ping the target maintainers.

@daltentry or @gilamn5tr would one of you mind double checking this?

@xingxue-ibm
Copy link
Contributor Author

One minor nit from me. I don't see anything concerning, but also don't know the platform so I'll ping the target maintainers.

@daltentry or @gilamn5tr would one of you mind double checking this?

@daltenty

@gilamn5tr
Copy link

LGTM from the AIX side.

@xingxue-ibm xingxue-ibm force-pushed the enable-aix-libc-test branch from 6c81afa to accc52e Compare May 13, 2025 13:35
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

Thanks!

@tgross35 tgross35 enabled auto-merge May 13, 2025 14:05
@tgross35 tgross35 disabled auto-merge May 13, 2025 15:27
Comment on lines 71 to 74
// Address must be a multiple of 0x4 for testing on AIX.
#[cfg(target_os = "aix")]
if cmsg_len % std::mem::size_of::<cmsghdr>() != 0 {
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I missed this one. Could you also replace #[cfg(...)] with cfg!(...) && in the if statement?

Avoiding #[cfg(...)] when possible is ideal because it keeps things from accidentally breaking even though we don't test aix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that makes sense. Thanks again!

@xingxue-ibm xingxue-ibm force-pushed the enable-aix-libc-test branch from accc52e to 8c97246 Compare May 13, 2025 15:50
@tgross35 tgross35 enabled auto-merge May 13, 2025 15:53
auto-merge was automatically disabled May 13, 2025 16:05

Head branch was pushed to by a user without write access

@xingxue-ibm xingxue-ibm force-pushed the enable-aix-libc-test branch from 8c97246 to c192a5c Compare May 13, 2025 16:05
@tgross35 tgross35 enabled auto-merge May 13, 2025 21:24
@tgross35 tgross35 disabled auto-merge May 13, 2025 21:25
@tgross35 tgross35 enabled auto-merge May 13, 2025 21:26
@tgross35 tgross35 added this pull request to the merge queue May 14, 2025
Merged via the queue into rust-lang:main with commit 151c3a9 May 14, 2025
96 of 102 checks passed
@xingxue-ibm
Copy link
Contributor Author

Hi @tgross35, Since this patch fixes functional definitions and declarations that affect AIX users, we’re wondering if it would be possible to cherry-pick it into the stable branch.

I’ve created a draft PR libc v0.2 cherry-pick: Enable libc-test and fix definitions/declarations for AIX #4455 which applies the cherry-pick with minor merge conflict resolutions in libc-test/build.rs and src/unix/aix/mod.rs.

Additionally, I had to modify src/unix/mod.rs in the PR to specify the correct type *const *mut for the execv*() function arguments for AIX to run the CI on AIX successfully. This was already fixed for all platforms in the main branch.

The CI for the draft PR failed in the ubuntu-24.04 test, but the failure doesn’t appear to be related to the changes in the PR, IIUC. @gilamn5tr @daltenty

@tgross35
Copy link
Contributor

No need to open a PR (but thank you for putting one up); just add the label and it will get into the next release 👍. I do them in batches to avoid conflicts from out of order picks.

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label May 16, 2025
@xingxue-ibm
Copy link
Contributor Author

No need to open a PR (but thank you for putting one up); just add the label and it will get into the next release 👍. I do them in batches to avoid conflicts from out of order picks.

Got it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix 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