Compile a NativeLibrary with NativeAOT
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 144
Description
**Is your feature request related to a problem? Please describe.**
I tried to use the new .NET 7 NativeAOT NativeLibrary feature in F#, adapting the C# [official example](https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrary) into the following code:
```fsharp
// My attempt to expose a simple function in a Native Library build.
namespace HelloLib
open System.Runtime.InteropServices
module Say =
[]
let hello name =
printfn "Hello %s" name
```
Unfortunately, the F# compiler just returned a generic `This attribute is currently unsupported by the F# compiler. Applying it will not achieve its intended effect.`
This is frustrating because there is [this lovely 3 year old example of doing an F# native library in .NET SDK version 3](https://secanablog.wordpress.com/2020/02/01/writing-a-native-library-in-f-which-can-be-called-from-c/), which makes it seem like the current lack of support is a bit of a regression compared to the state of Native AOT in 2020.
**Describe the solution you'd like**
I would like F# to support building a NativeLibrary. Short of this, adding some newbie-friendly information to the F# documentation explaining the current state of Native AOT and the expectation for future support would also be helpful.
**Describe alternatives you've considered**
I have considered trying to wrap an F# library in a C# native library, but that feels like too much of a hack. I also am a .NET and compilers novice, so I'm not sure that this approach would even work. If this would likely work and is actually a good workaround at the moment, any pointers as to how to accomplish this would also be appreciated!
dotnet --info output
```console
dotnet --info
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: manjaro
OS Version:
OS Platform: Linux
RID: manjaro-x64
Base Path: /usr/share/dotnet/sdk/7.0.102/
Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb
.NET SDKs installed:
7.0.102 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
Contributor guide
Assessment
This issue has not been assessed yet.