microsoft / cppwinrt

C++/WinRT
MIT License
1.64k stars 238 forks source link

Add Linux native build #1239

Closed alvinhochun closed 1 year ago

alvinhochun commented 1 year ago

Depends on https://github.com/microsoft/cppwinrt/pull/1238 and https://github.com/microsoft/winmd/pull/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.

alvinhochun commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

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

alvinhochun commented 1 year ago

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 commented 1 year ago

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

kennykerr commented 1 year ago

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

alvinhochun commented 1 year ago

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 commented 1 year ago

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

kennykerr commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Thanks!