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 .NET native AOT support #32

Closed
stevefan1999-personal opened this issue Jul 21, 2022 · 8 comments
Closed

Add .NET native AOT support #32

stevefan1999-personal opened this issue Jul 21, 2022 · 8 comments
Labels
处置:完成(Done) 影响范围:低 这个问题不会造成真正的体验问题,可以暂缓解决。 类型:新功能/建议(enhancement) New feature or request

Comments

@stevefan1999-personal
Copy link

stevefan1999-personal commented Jul 21, 2022

Perhaps we can find a way to run ,NET but natively compiled down version. Because if Rust can be dealt with, why not .NET, or even Golang?

VC-LTL v5.0.10-Beta2版本开始已经兼容了.NET Native AOT

使用方法

  1. 从NuGet中安装VC-LTL v5.0.10-Beta2
  2. TargetFramework,需要调整为net8.0-windows,这样默认就是兼容Windows 7 RTM
    • VC-LTL会自动依赖YY-Thunks,无需人工干预
  3. 如果需要兼容Windows XP,请将添加<SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>

csproj文件示例

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net8.0-windows</TargetFramework>
        <!--如果不支持XP这一行不需要添加SupportedOSPlatformVersion-->
        <SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
        <!--...-->
    </PropertyGroup>
   <!--...-->
</Project>
@mingkuang-Chuyu mingkuang-Chuyu added the 影响范围:低 这个问题不会造成真正的体验问题,可以暂缓解决。 label Apr 5, 2023
@stevefan1999-personal
Copy link
Author

After some research I think this is actually possible, take a look at this:

https://github.com/dotnet/runtime/blob/d3ab95d3be895a1950a46c559397780dbb3e9807/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets

Maybe we can just find a way to override the MSBuild property SdkNativeLibrary to inject VC-LTL based libraries in Microsoft.NETCore.Native.Windows.targets?

@stevefan1999-personal
Copy link
Author

image
There it goes:

    <ItemGroup>
      <SdkNativeLibrary Include="advapi32.lib" />
      <SdkNativeLibrary Include="bcrypt.lib" />
      <SdkNativeLibrary Include="crypt32.lib" />
      <SdkNativeLibrary Include="iphlpapi.lib" />
      <SdkNativeLibrary Include="kernel32.lib" />
      <SdkNativeLibrary Include="mswsock.lib" />
      <SdkNativeLibrary Include="ncrypt.lib" />
      <SdkNativeLibrary Include="normaliz.lib" />
      <SdkNativeLibrary Include="ntdll.lib" />
      <SdkNativeLibrary Include="ole32.lib" />
      <SdkNativeLibrary Include="oleaut32.lib" />
      <SdkNativeLibrary Include="secur32.lib" />
      <SdkNativeLibrary Include="user32.lib" />
      <SdkNativeLibrary Include="version.lib" />
      <SdkNativeLibrary Include="ws2_32.lib" />
      <SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\6.2.9200.0\lib\x64\libucrt.lib" />
      <SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\6.2.9200.0\lib\x64\libvcruntime.lib" />
    </ItemGroup>
    <ItemGroup Condition="!Exists('$(IlcSdkPath)debugucrt.txt')">
      <!-- Force ucrt to be dynamically linked for release runtime -->
      <LinkerArg Include="/NODEFAULTLIB:ucrt.lib" />
      <LinkerArg Include="/NODEFAULTLIB:vcruntime.lib" />
      <LinkerArg Include="/DEFAULTLIB:libucrt.lib" />
      <LinkerArg Include="/DEFAULTLIB:libvcruntime.lib" />
    </ItemGroup>

@stevefan1999-personal
Copy link
Author

stevefan1999-personal commented Jan 12, 2024

Yep, just adding these few to csproj, should work on any project:

	<ItemGroup>
		<SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\5.2.3790.0\lib\x64\libucrt.lib" />
		<SdkNativeLibrary Include="F:\VC-LTL-5.0.9-Binary\TargetPlatform\5.2.3790.0\lib\x64\libvcruntime.lib" />
		<LinkerArg Include="/DEFAULTLIB:libucrt.lib" />
		<LinkerArg Include="/DEFAULTLIB:libvcruntime.lib" />
		<LinkerArg Include="/NODEFAULTLIB:ucrt.lib" />
		<LinkerArg Include="/NODEFAULTLIB:vcruntime.lib" />
	</ItemGroup>

So what we need to figure out is how to add the MSBuild support and publish the right version on Nuget...

@MouriNaruto
Copy link
Member

Looks good.

Kenji Mouri

@mingkuang-Chuyu mingkuang-Chuyu added the 处置:等待发布(Publishing) 问题已经解决,等待新版本发布。 label May 4, 2024
@mingkuang-Chuyu
Copy link
Collaborator

@mingkuang-Chuyu mingkuang-Chuyu added 处置:完成(Done) and removed 处置:等待发布(Publishing) 问题已经解决,等待新版本发布。 labels May 4, 2024
@stevefan1999-personal
Copy link
Author

stevefan1999-personal commented May 6, 2024

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package?

@mingkuang-Chuyu
Copy link
Collaborator

mingkuang-Chuyu commented May 6, 2024

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package?
README will update, thanks~

  1. Install YY-Thunks v5.0.10-Beta2 or leater
  2. modify the value of TargetFramework to net8.0-windows
  3. optional, if you need run on Windows XP, please modify the value of SupportedOSPlatformVersion to 5.1

@stevefan1999-personal
Copy link
Author

新版本已经发布 https://github.com/Chuyu-Team/VC-LTL5/releases/tag/v5.0.10-Beta2

There could be a new README section about how it works, does it just work by installing the Nuget package?
README will update, thanks~

  1. Install YY-Thunks v5.0.10-Beta2 or leater
  2. modify the value of TargetFramework to net8.0-windows
  3. optional, if you need run on Windows XP, please modify the value of SupportedOSPlatformVersion to 5.1

Can confirm it worked like a charm:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <InvariantGlobalization>true</InvariantGlobalization>
	<TargetFramework>net8.0-windows</TargetFramework>
    <!--如果不支持XP这一行不需要添加SupportedOSPlatformVersion-->
    <SupportedOSPlatformVersion>5.1</SupportedOSPlatformVersion>
	<OptimizationPreference>Size</OptimizationPreference>
	<TrimMode>copyused</TrimMode>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="VC-LTL" Version="5.0.10-Beta2" />
    <PackageReference Include="YY-Thunks" Version="1.0.10-Beta3" />
  </ItemGroup>

</Project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
处置:完成(Done) 影响范围:低 这个问题不会造成真正的体验问题,可以暂缓解决。 类型:新功能/建议(enhancement) New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants