-
Notifications
You must be signed in to change notification settings - Fork 5k
[NativeAOT] Add ability to generate library and exe entry points #81873
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
Merged
MichalStrehovsky
merged 7 commits into
dotnet:main
from
AustinWise:austin/CustomNativeAotMain
Feb 15, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f81e27d
[NativeAot] Add ability to generate library and exe entry points
AustinWise 8fdb3dd
Add build integration and test for using split entry point
AustinWise e4e8c53
Add missing copyright headers.
AustinWise db756f4
Use ModuleInitializer rather than class constructor in test
AustinWise 8a27286
Shorten flag name to --splitinit
AustinWise 960aa86
Add back the static constructor
AustinWise 9b9be9e
Fix test build.
AustinWise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
project (CustomMainNative) | ||
include_directories(${INC_PLATFORM_DIR}) | ||
|
||
add_library (CustomMainNative STATIC CustomMainNative.cpp) | ||
|
||
# add the install targets | ||
install (TARGETS CustomMainNative DESTINATION bin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
class Program | ||
{ | ||
// Each of the module initializer, class constructor, and IncrementExitCode | ||
// should be executed exactly once, causing this to each 100 by program exit. | ||
static int s_exitCode; | ||
|
||
[ModuleInitializer] | ||
internal static void InitializeModule() | ||
{ | ||
s_exitCode += 8; | ||
} | ||
|
||
static Program() | ||
{ | ||
s_exitCode += 31; | ||
// A side-effecting operation to prevent this cctor from being pre-inited at compile time. | ||
Console.WriteLine("hello from static constructor"); | ||
} | ||
|
||
[UnmanagedCallersOnly(EntryPoint = "IncrementExitCode", CallConvs = new Type[] { typeof(CallConvCdecl) })] | ||
static void IncrementExitCode(int amount) | ||
{ | ||
s_exitCode += amount; | ||
} | ||
|
||
int ExitCode; | ||
|
||
static int Main(string[] args) | ||
{ | ||
Console.WriteLine("hello from managed main"); | ||
return s_exitCode; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<CustomNativeMain>true</CustomNativeMain> | ||
<StaticLibraryPrefix Condition="'$(TargetOS)' != 'windows'">lib</StaticLibraryPrefix> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="CustomMain.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<CMakeProjectReference Include="CMakeLists.txt" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<NativeLibrary Include="$(OutputPath)$(StaticLibraryPrefix)CustomMainNative$(LibFileExt)" /> | ||
</ItemGroup> | ||
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#include <stdio.h> | ||
#include <stdint.h> | ||
|
||
#if defined(_WIN32) | ||
extern "C" int __managed__Main(int argc, wchar_t* argv[]); | ||
#else | ||
extern "C" int __managed__Main(int argc, char* argv[]); | ||
#endif | ||
|
||
extern "C" void IncrementExitCode(int32_t amount); | ||
|
||
#if defined(_WIN32) | ||
int __cdecl wmain(int argc, wchar_t* argv[]) | ||
#else | ||
int main(int argc, char* argv[]) | ||
#endif | ||
{ | ||
puts("hello from native main"); | ||
IncrementExitCode(61); | ||
return __managed__Main(argc, argv); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.