Skip to content

Conversation

@martinjlowm
Copy link

@martinjlowm martinjlowm commented Nov 9, 2025

Issues:

Not reported.

Description of changes:

aws-ls-sys fails to build via Nix (crate2nix) due to missing typedefs, presumably because the Clang used from the Nix sandbox doesn't set -D_DARWIN_C_SOURCE.

The content of interest is https://github.com/alexey-lysiuk/macos-sdk/blob/main/MacOSX26.1.sdk/usr/include/sys/types.h#L83-L96 which doesn't evaluate unless _DARWIN_C_SOURCE is set. The first POSIX branch is set because __STDC_ALLOC_LIB__ isn't: https://github.com/aws/aws-lc/blob/main/crypto/err/err.c#L113C8-L117

I suppose _POSIX_C_SOURCE was set for a reason and I can't figure out why a normal Cargo build would work - I cannot find any trace of __STDC_ALLOC_LIB__ - apart from a comment in #610.

The absence of _DARWIN_C_SOURCE causes the CC builder to throw:

In file included from /nix/var/nix/builds/nix-37298-3130532386/aws-lc-sys-0.32.3/aws-lc/crypto/fipsmodule/bcm.c:78:
In file included from /nix/var/nix/builds/nix-37298-3130532386/aws-lc-sys-0.32.3/aws-lc/crypto/fipsmodule/cpucap/cpu_aarch64_apple.c:20:
In file included from /nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/sysctl.h:83:
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/ucred.h:101:2:
error: unknown type name 'u_int'
  101 |         u_int   cr_version;             /* structure layout version */
      |         ^
In file included from /nix/var/nix/builds/nix-37298-3130532386/aws-lc-sys-0.32.3/aws-lc/crypto/fipsmodule/bcm.c:78:
In file included from /nix/var/nix/builds/nix-37298-3130532386/aws-lc-sys-0.32.3/aws-lc/crypto/fipsmodule/cpucap/cpu_aarch64_apple.c:20:
In file included from /nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/sysctl.h:85:
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:116:2: error: unknown type name 'u_int'
  116 |         u_int   p_estcpu;        /* Time averaged value of p_cpticks. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:121:2: error: unknown type name 'u_int'
  121 |         u_int   p_swtime;        /* Time swapped in or out. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:122:2: error: unknown type name 'u_int'
  122 |         u_int   p_slptime;       /* Time since last blocked. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:136:2: error: unknown type name 'u_char'; did you mean 'char'?
  136 |         u_char  p_priority;     /* Process priority. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:137:2: error: unknown type name 'u_char'; did you mean 'char'?
  137 |         u_char  p_usrpri;       /* User-priority based on p_cpu and p_nice. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:142:2: error: unknown type name 'u_short'; did you mean 'short'?
  142 |         u_short p_xstat;        /* Exit status for wait; also stop signal. */
      |         ^
/nix/store/6py65dicilvc6qxfra4mzw0xpxw2vc06-apple-sdk-11.3/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/proc.h:143:2: error: unknown type name 'u_short'; did you mean 'short'?
  143 |         u_short p_acflag;       /* Accounting flags. */
      |         ^

Call-outs:

This is unfamiliar territory for me. I don't know if configuring _POSIX_C_SOURCE appropriately is the better option.

Testing:

N/A

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

@martinjlowm martinjlowm requested a review from a team as a code owner November 9, 2025 22:25
Comment on lines +386 to +387
// Certain MacOS system headers are guarded by _POSIX_C_SOURCE and _DARWIN_C_SOURCE
new_cflags.push_str(" -D_DARWIN_C_SOURCE");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is likely not the best place to add this flag. I'll update this PR and try to add a CI job for nix.

Copy link
Author

Choose a reason for hiding this comment

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

Hey Justin - I have a small reproducible example I can share for our crate2nix fork. You should be able to incorporate this into a CI job

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that would be appreciated. My understanding of Nix is currently limited. 😀

Copy link
Contributor

@justsmth justsmth Nov 11, 2025

Choose a reason for hiding this comment

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

Based on the output you shared, I'm thinking that the best place for this change might be upstream in AWS-LC -- specifically above this line in cpu_aarch64_apple.c. But I would need to test it.

I think we ahould also be able to reproduce this issue upstream in AWS-LC. We do test w/ Nix, but perhaps not for this target.

Copy link
Author

Choose a reason for hiding this comment

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

https://github.com/martinjlowm/crate2nix-aws-lc-mr here goes - the step to run is documented in the README. I assume you have Nix installed already.

@codecov-commenter
Copy link

codecov-commenter commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.36%. Comparing base (c358484) to head (4311944).
⚠️ Report is 280 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #941      +/-   ##
==========================================
- Coverage   95.80%   92.36%   -3.44%     
==========================================
  Files          61       73      +12     
  Lines        8143     9659    +1516     
  Branches        0     9659    +9659     
==========================================
+ Hits         7801     8922    +1121     
- Misses        342      450     +108     
- Partials        0      287     +287     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Successfully merging this pull request may close these issues.

3 participants