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 Linux native build #1239

Merged
merged 17 commits into from
Dec 6, 2022
Merged

Conversation

alvinhochun
Copy link
Contributor

Depends on #1238 and microsoft/winmd#28

This adds support for building a native Linux executable of cppwinrt. It works mostly the same as on Windows, except without the code that searches for Windows SDKs and local WinMetadata.

For reasons yet unknown to me, GCC 11 on Ubuntu 22.04 emits references
to the `extern char const _[]` declarations inside `strings.h` without
C++ name mangling applied, causing link errors. Wrapping the
declarations inside `extern "C++"` fixes this issue somehow, so this
change does exactly it.
@alvinhochun
Copy link
Contributor Author

I did test the native Linux build with a copy of Windows.winmd from Windows SDK 19041 and it outputs the exact same headers as a native Windows build. But I can't add a CI check for this because there is no way to get the Windows.winmd file for use on Linux. Is there any way to get this winmd file without having to install the full Windows SDK?

@kennykerr
Copy link
Collaborator

We could include the winmd in the repo just for CI validation. That's what I do here for Rust:

/~https://github.com/microsoft/windows-rs/tree/master/crates/libs/metadata/default

@kennykerr
Copy link
Collaborator

Almost forgot - there is a nuget package with just the winmd files:

https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts/

@alvinhochun
Copy link
Contributor Author

Ah, neat that it is included in windows-rs. I could just download the file from there as part of the workflow. Committing the file into the repo may be an option too, but I wonder if it should be done for just one CI check...

While we are on this topic, will you be able to clarify the license of the winmd files? Since the merged Windows.winmd file has been committed into the windows-rs repo (and published as part of a crate), which is dual-licensed under MIT and Apache 2.0, can I conclude that the Windows.winmd file is also under the same licenses?

I ask because there are concerns about the license of the generated headers. If someone as a third party generates the headers using the winmd files shipped with either Windows or the WinSDK, it is not clear whether the generated headers are clean in regard to licensing. If we do have a source of the winmd file licensed under MIT, then there should be no more licensing issues with the generated headers. This brings us back to the question whether we should include the winmd file in this repo -- if it can indeed be licensed under MIT, then it may be a good idea to include it in the repo not just for the CI check, but also to provide a copy of it next to the cppwinrt source which downstream can use.

(It would still be nice if there is a standalone package of the winmd files explicitly licensed under MIT though.)

@kennykerr
Copy link
Collaborator

Right, everything in the windows-rs repo is dual licensed so that would include the winmd files.

@kennykerr
Copy link
Collaborator

I sent you an invite to give you permission to re-run workflows as needed.

@alvinhochun
Copy link
Contributor Author

I sent you an invite to give you permission to re-run workflows as needed.

Thanks! Looking at the latest failure, I think I should try using actions/cache@v3 action to avoid downloading the same dependencies repeatedly. Has this action been allowed in the repo settings?

@kennykerr
Copy link
Collaborator

Yes, that's what I use on windows-rs - I've enabled it here as well.

@alvinhochun alvinhochun marked this pull request as ready for review December 6, 2022 12:39
@@ -3,6 +3,7 @@
#include <cassert>
#include <array>
#include <limits>
#include <climits>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious what this is for, as opposed to limits...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Line 316 has static constexpr uint32_t no_max = UINT_MAX;

@kennykerr
Copy link
Collaborator

Something seems to be wrong with the test validation. It doesn't seem to break the build anymore.

/~https://github.com/microsoft/cppwinrt/actions/runs/3628603087/jobs/6120073812#step:7:44

@alvinhochun
Copy link
Contributor Author

Something seems to be wrong with the test validation. It doesn't seem to break the build anymore.

/~https://github.com/microsoft/cppwinrt/actions/runs/3628603087/jobs/6120073812#step:7:44

This test is marked for Clang "shouldfail" because libc++ does not yet support source_location, so this is expected.

@kennykerr
Copy link
Collaborator

Thanks!

@kennykerr kennykerr merged commit 4a5acf6 into microsoft:master Dec 6, 2022
@alvinhochun alvinhochun deleted the alvin/linux-build branch December 11, 2022 16:49
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.

2 participants