Compile C/C++ code statically and link together at build time for NativeAOT? #96937
-
For example, I want to bundle sqlite3 statically with NativeAOT rather than with dynamic libraries, so that we could enjoy link time optimization, right now this is what I do:
I have to compile the
(Technically speaking, just supplying an object file is good enough as there is just one sqlite3.c translation unit) But this got me thinking, why can't we also bundle the C/C++ source code as part of a MSBuild process to compile those file on the fly and add them to SdkNativeLibrary altogether? Like we can invoke an external compiler to run the MSVC to build the sqlite3 library. Kinda like how you can link libraries together with vcxproj. So basically what I wanted is something similar to the Related discussion: ericsink/SQLitePCL.raw#582 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You can run arbitrary commands with the
Obviously, this isn't as good as an actual integration.... at minimum you'd have to play around with targets and other things to get it to handle build dependencies properly. |
Beta Was this translation helpful? Give feedback.
-
For a sample of how to combine C# and C++ projects, see https://github.com/dotnet/samples/tree/main/core/interop/IDynamicInterfaceCastable/src.
Link time optimizations assume that instead of native code, the inputs to the linker contain special bytecode known to the Visual C++ compiler (linker will invoke the Visual C++ compiler to generate native code). Native AOT compiler doesn't produce outputs in LTO format because the LTO format is Visual C++ compiler specific. I don't think you'll see benefits of LTO outside sqlite3.lib (which will be the only compiland with LTO bytecode).
I suggest using the documented |
Beta Was this translation helpful? Give feedback.
For a sample of how to combine C# and C++ projects, see https://github.com/dotnet/samples/tree/main/core/interop/IDynamicInterfaceCastable/src.
Link time optimizations assume that instead of native code, the inputs to the linker contain special bytecode known to the Visual C++ compiler (linker will invoke the Visual C++ compiler to generate native code). Native AOT compiler doesn't produce outputs in LTO format because the LTO format is Visual C++ compiler specific. I don't think you'll see benefits of LTO outside sqlite3.lib (which will be the only compiland with LTO bytecode).
I suggest using the documented
<NativeLibrary>
…