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 7 target, update dependencies, run tests on all supported target monikers #14

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "6.2.1",
"version": "7.2.1",
"commands": [
"paket"
]
Expand Down
32 changes: 32 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Auto detect text files and perform LF normalization
* text=auto eol=lf

# Custom for Visual Studio
*.cs text diff=csharp
*.sln text eol=crlf merge=union
*.csproj text merge=union
*.vbproj text merge=union
*.fsproj text merge=union
*.dbproj text merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

*.sh text eol=lf
*.cmd text eol=crlf
*.bat text eol=crlf

*.png binary
*.exe binary

# correct file type displays in gitlab to not be so overwhelmingly HTML
tests/FSharp.Data.Tests/Data/**.htm* -linguist-detectable
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source https://api.nuget.org/v3/index.json

storage: none
framework: net5.0, net6.0
framework: net5.0, net6.0, net7.0

nuget Argu
nuget coverlet.collector
Expand Down
610 changes: 91 additions & 519 deletions paket.lock

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions src/fasmi/Compilation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ open System
open FileSystem
open FSharp.Compiler.CodeAnalysis

// the Assembly attribute to build output as net5.0/net6.0
// the Assembly attribute to build output as net5.0/net6.0/net7.0

let netAttr =
#if NET6_0
#if NET7_0
"""
namespace Microsoft.BuildSettings
[<System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v7.0", FrameworkDisplayName="")>]
do ()
"""
#endif
#if NET6_0
"""
namespace Microsoft.BuildSettings
[<System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName="")>]
Expand All @@ -24,7 +31,7 @@ do ()

let netAttrName = "NetAssemblyAttr.fs"

// check the net5.0/net6.0 assembly attribute file exists or create it
// check the net5.0/net6.0/net7.0 assembly attribute file exists or create it
let ensureNetAttr asmPath =
let filePath = dir asmPath </> netAttrName
if not (IO.File.Exists filePath) then
Expand All @@ -39,8 +46,13 @@ let compile (path: string) (asmPath: string) =
// find .net assembly path
let netPath =
let runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()
#if NET7_0
let packDir =
IO.Directory.GetDirectories(runtimeDir </> "../../../packs/Microsoft.NETCore.App.Ref/", "7.0.*")
|> Seq.max
IO.Path.GetFullPath(packDir </> "ref/net7.0")
#endif
#if NET6_0

let packDir =
IO.Directory.GetDirectories(runtimeDir </> "../../../packs/Microsoft.NETCore.App.Ref/", "6.0.*")
|> Seq.max
Expand All @@ -64,6 +76,10 @@ let compile (path: string) (asmPath: string) =
"--define:NETCOREAPP"
"--define:NET5_0"
"--define:NET5_0_OR_GREATER"
#if NET7_0
"--define:NET7_0"
"--define:NET7_0_OR_GREATER"
#endif
#if NET6_0
"--define:NET6_0"
"--define:NET6_0_OR_GREATER"
Expand Down
2 changes: 1 addition & 1 deletion src/fasmi/fasmi.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<PackAsTool>true</PackAsTool>
<ToolCommandName>fasmi</ToolCommandName>
<PackageOutputPath>./nuget</PackageOutputPath>
Expand Down
6 changes: 6 additions & 0 deletions tests/fasmi.tests.source/Source.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ let abs x =

let toString (x: int) =
x.ToString()

type HelloWriter(x) =
member this.Hello() = System.Console.WriteLine $"hello {x}"

let sayHello (x: int) =
HelloWriter(x).Hello()
2 changes: 1 addition & 1 deletion tests/fasmi.tests.source/fasmi.tests.source.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

Expand Down
37 changes: 13 additions & 24 deletions tests/fasmi.tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ open Xunit
// generated asm is platform sensitive due to differences in call conventions
let isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)

// normalize line endings for string comparions
let normalizeLineEnds (s: string) =
if isWindows then
s
else
s.Replace("\r\n", "\n")

module Assert =
let EqualString(x, y) = Assert.Equal(normalizeLineEnds x, normalizeLineEnds y)


// disassemble en single method from the fasmi.tests.source project
// notice that this project is *ALWAYS* compiled in release to produce
// the same optimized IL.
Expand All @@ -31,7 +20,7 @@ let disassembleFromSourceProject methodName =
failwith $"Function '%s{methodName}' not found"

Disassembly.withRuntime (fun runtime ->
use writer = new IO.StringWriter()
use writer = new IO.StringWriter(NewLine="\n")
Disassembly.disassembleMethod runtime mth Disassembly.Platform.X64 false writer
writer.Flush()
writer.ToString())
Expand All @@ -57,39 +46,39 @@ L0000: lea eax, [rdi+1]
L0003: ret
"""

Assert.EqualString(expected, output)
Assert.Equal(expected, output)

[<Fact>]
let ``jump label should be generated`` () =
let output = disassembleFromSourceProject "abs"
let lines = (normalizeLineEnds output).Split(Environment.NewLine)
let lines = output.Split("\n")
// we look only at the conditional jump 'jl' line
// others are different due call conventions
let jumpLine =
lines
|> Array.find (fun l -> l.Contains "jl")

// the full label can be different because emited ASM has different size
// the full label can be different because emitted ASM has different size
// depending on the platform, so we check only the first chars.
// we also omit checking the label at the start of the line
let expected = "jl short L00"
Assert.Contains(expected, jumpLine)


[<Fact>]
let ``when calling function, call must contain function name`` () =
let ``when calling system method, call must contain method name`` () =
let output = disassembleFromSourceProject "toString"

let lines = (normalizeLineEnds output).Split(Environment.NewLine)
let callLine =
lines
|> Array.find (fun l -> l.Contains "call")

// we omit checking the label at the start of the line
// because it can be different on different platforms
let expected = "call System.Number.Int32ToDecStr(Int32)"
Assert.Contains(expected, callLine)

Assert.Contains(expected, output)

[<Fact>]
let ``when calling local method, call must contain method name`` () =
let output = disassembleFromSourceProject "sayHello"
// we omit checking the label at the start of the line
// because it can be different on different platforms
let expected = "call Source+HelloWriter.Hello()"
Assert.Contains(expected, output)


2 changes: 1 addition & 1 deletion tests/fasmi.tests/fasmi.tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net5.0;net6.0;net7.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<GenerateProgramFile>true</GenerateProgramFile>
</PropertyGroup>
Expand Down