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

Add property(ies) to Context describing the target triple #7929

Open
grynspan opened this issue Aug 29, 2024 · 9 comments
Open

Add property(ies) to Context describing the target triple #7929

grynspan opened this issue Aug 29, 2024 · 9 comments
Labels
enhancement package manifests changes to package manifest APIs

Comments

@grynspan
Copy link
Contributor

There are various scenarios under which it would be useful to be able to get the target triple, or components thereof, as defined by LLVM. Would be great if we could expose that information via Context to the package manifest.

@grynspan grynspan added enhancement package manifests changes to package manifest APIs labels Aug 29, 2024
@grynspan
Copy link
Contributor Author

See also #7110.

@dschaefer2
Copy link
Member

Can you be more explicit about the scenarios you're thinking where the manifest would need to know the triple?

I really worry about exposing this to the package manifest. As I dig into cross compilation scenarios especially for distributed systems that you probably want to build from a monorepo with a single package manifest with multiple triples, we'll likely need to make changes to how that works.

@grynspan
Copy link
Contributor Author

For Swift Testing, having this information as a string (rather than forcing us to ask 20 questions with arch() and os() checks) would be useful for diagnostic purposes. For instance, when we get a bug report with a crash, it helps to know what the target architecture/OS is at-a-glance.

I can see this also being useful for manifest authors that need to change specific compiler settings depending on architecture, e.g. enabling/disabling ptrauth instructions on arm64 or opting out of AVX instructions on Intel (because you know you're going to deploy to chips that don't support them.) That doesn't necessarily require the same API, as we could augment .when() to allow for architectures and not just OSes.

@dschaefer2
Copy link
Member

For Swift Testing, having this information as a string (rather than forcing us to ask 20 questions with arch() and os() checks) would be useful for diagnostic purposes. For instance, when we get a bug report with a crash, it helps to know what the target architecture/OS is at-a-glance.

That sounds like you need something at run time, not package resolution time.

I can see this also being useful for manifest authors that need to change specific compiler settings depending on architecture, e.g. enabling/disabling ptrauth instructions on arm64 or opting out of AVX instructions on Intel (because you know you're going to deploy to chips that don't support them.) That doesn't necessarily require the same API, as we could augment .when() to allow for architectures and not just OSes.

I'm definitely interested in extending where .when() can be applied and what types of conditions you can when on.

@grynspan
Copy link
Contributor Author

That sounds like you need something at run time, not package resolution time.

I need the value at runtime, but package build time is when the value is determined. I can't just go ask the Swift runtime (for example) for the info because the triple used to build the Swift runtime may not match the triple used to build my package.

@dschaefer2
Copy link
Member

That sounds like you need something at run time, not package resolution time.

I need the value at runtime, but package build time is when the value is determined. I can't just go ask the Swift runtime (for example) for the info because the triple used to build the Swift runtime may not match the triple used to build my package.

You can mix triples at link time?

@grynspan
Copy link
Contributor Author

Perhaps not statically within the same module (maybe you can?) but a module compiled with triple arm64e-apple-macosx12.0 could link to one compiled with triple arm64-apple-macosx12.4 (in theory, anyway—I don't know offhand if that specific combination is valid.)

@dschaefer2
Copy link
Member

I guess my main thinking here is that I don't want to lock us into only one triple for a build like CMake has. CMake's toolchain stuff is totally bolted on and limits its use in monorepos. We pass -triple to the compiler at build time, we could also set a macro but ideally the compiler itself sets a macro.

@grynspan
Copy link
Contributor Author

I've reached out to the clang folks about setting a macro on their end, but I'm exploring all options here. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement package manifests changes to package manifest APIs
Projects
None yet
Development

No branches or pull requests

2 participants