Skip to content

Commit

Permalink
Update .NET, Paket, Fake, packages, build scripts
Browse files Browse the repository at this point in the history
We have replaced Fake CLI with a project in order to use .NET 7.0. See
fsprojects/FAKE#2719 and
https://fake.build/guide/getting-started.html#Run-FAKE-using-a-dedicated-build-project
. We are not sure if the resulting solution is optimal or "best practice".
  • Loading branch information
ivar-rummelhoff committed May 24, 2023
1 parent 9f45775 commit cc3182b
Show file tree
Hide file tree
Showing 19 changed files with 380 additions and 446 deletions.
8 changes: 1 addition & 7 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
"version": 1,
"isRoot": true,
"tools": {
"fake-cli": {
"version": "5.20.4",
"commands": [
"fake"
]
},
"paket": {
"version": "6.0.13",
"version": "7.2.1",
"commands": [
"paket"
]
Expand Down
2 changes: 1 addition & 1 deletion Assembler.Tests/Assembler.Tests.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>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Assembler/Assembler.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.1.2</RuntimeFrameworkVersion>
<TargetFramework>net7.0</TargetFramework>
<RuntimeFrameworkVersion>7.0.5</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="Ast.fs" />
Expand Down
4 changes: 2 additions & 2 deletions Command/Command.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.1.2</RuntimeFrameworkVersion>
<TargetFramework>net7.0</TargetFramework>
<RuntimeFrameworkVersion>7.0.5</RuntimeFrameworkVersion>
<AssemblyName>ivm</AssemblyName>
<AssemblyVersion>$(VERSION)</AssemblyVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Machine.Tests/Machine.Tests.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>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Machine/Machine.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.1.2</RuntimeFrameworkVersion>
<TargetFramework>net7.0</TargetFramework>
<RuntimeFrameworkVersion>7.0.5</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="Instructions.fs" />
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ Zip files containing executables for Linux, Windows and MacOS have been attached

## Building the assembler from source

The Bash script `publish.sh` builds the assembler, runs the tests and creates the deployment zip-files for all three platforms. In order to run the script, you need .NET Core. (If you do not have Bash, you can execute the three dotnet commands in the script manually.)
The Bash script `build.sh` builds the assembler, runs the tests and creates the deployment zip-files for all three platforms. In order to run the script, you need .NET. If you do not have Bash, you can execute the three dotnet commands in the script manually.

Pass `Clean` or `Test` as argument to `build.sh` in order to only clean the directories or run the unit tests.

## Machine implementations

Expand Down
2 changes: 1 addition & 1 deletion Tools.Tests/Tools.Tests.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>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Tools/Tools.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeFrameworkVersion>3.1.2</RuntimeFrameworkVersion>
<TargetFramework>net7.0</TargetFramework>
<RuntimeFrameworkVersion>7.0.5</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers.fs" />
Expand Down
99 changes: 0 additions & 99 deletions build.fsx

This file was deleted.

13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

# See https://stackoverflow.com/a/3355423
cd "$(dirname "$0")"

dotnet tool restore
dotnet paket restore

# See https://github.com/TheAngryByrd/MiniScaffold/blob/master/build.sh
FAKE_DETAILED_ERRORS=true dotnet run --project ./build/build.fsproj -- -t "$@"
99 changes: 99 additions & 0 deletions build/build.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
open Fake.IO
open Fake.IO.Globbing.Operators //enables !! and globbing
open Fake.IO.FileSystemOperators
open Fake.Core
open Fake.DotNet
open Fake.Tools
open Fake.Core.TargetOperators

open System.Runtime.InteropServices


[<EntryPoint>]
let main argv =
argv
|> Array.toList
|> Context.FakeExecutionContext.Create false "build.fs"
|> Context.RuntimeContext.Fake
|> Context.setExecutionContext

Target.initEnvironment()

// From https://fake.build/guide/dotnet-cli.html#Minimal-working-example
let install = lazy DotNet.install DotNet.Versions.FromGlobalJson
let inline dotnetSimple arg = DotNet.Options.lift install.Value arg

Target.create "Clean" (fun _ ->
let res = DotNet.exec dotnetSimple "clean" "" // "ivm-implementations.sln"
if not res.OK then failwithf "'dotnet clean' failed with code %i" res.ExitCode
)

Target.create "Test" (fun _ ->
// TODO: Reduce output noise when running tests / running in general
DotNet.test dotnetSimple "."
)

// Since Git.Information.getLastTag only sees annotated tags
let getLastTag () =
Git.CommandHelper.getGitResult "." "describe --tags --abbrev=0" |> Seq.head

let publish (alsoZip: bool) (runtimes: string list) =
let framework = "net7.0"
let tag = getLastTag ()
let version = tag.Substring 1
Trace.log $"Publishing {tag}..."

for runtime in runtimes do
let releaseDir = "Command" </> "bin" </> "release" </> framework </> runtime
let publishDir = releaseDir </> "publish"

Shell.cleanDir publishDir

// Inspired by https://github.com/cannorin/flxble/blob/master/build.fsx
let opt (options: DotNet.PublishOptions) =
{
options with
Configuration = DotNet.BuildConfiguration.Release
SelfContained = Some true
Runtime = Some runtime

MSBuildParams =
{
options.MSBuildParams with
// DisableInternalBinLog = true // https://gitter.im/fsharp/FAKE?at=5e6a729be203784a55a350db
Properties =
("PackAsTool", "false")
:: ("TargetFramework", framework)
:: ("PublishSingleFile", "true")
:: ("PublishTrimmed", "true")
:: ("AssemblyVersion", version)
:: options.MSBuildParams.Properties
}
}
DotNet.publish (dotnetSimple >> opt) "Command"

if alsoZip then
// Put the executable and .pdb file in one zip file.
// This overwrites any existing zip file.
!! (publishDir </> "*") |> Zip.zip publishDir (releaseDir </> sprintf "%s_%s.zip" tag runtime)

// Publish and zip for all platforms (after clean and test)
Target.create "Publish" <| fun _ ->
publish true ["osx-x64"; "linux-x64"; "win-x64"]

// Publish for current platform
Target.create "Pub" <| fun _ ->
let runtime =
if RuntimeInformation.IsOSPlatform(OSPlatform.OSX) then "osx-x64"
else if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then "win-x64"
else "linux-x64"
publish false [runtime]

ignore <| [
"Clean" ==> "Publish"
"Clean" ?=> "Test"
"Test" ==> "Publish"
]

Target.runOrDefaultWithArguments "Publish"
0
11 changes: 11 additions & 0 deletions build/build.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="build.fs" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
5 changes: 5 additions & 0 deletions build/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fake.IO.FileSystem
Fake.IO.Zip
Fake.DotNet.Cli
Fake.Tools.Git
Fake.Core.Target
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "7.0.302",
"rollForward": "latestMinor"
}
}
2 changes: 1 addition & 1 deletion ivm-implementations.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28721.148
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down
5 changes: 4 additions & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ source https://api.nuget.org/v3/index.json

nuget AltCover
nuget Expecto
nuget Fake.Core.Target
nuget Fake.DotNet.Cli
nuget Fake.IO.Zip
nuget Fake.Tools.Git
nuget FParsec
nuget FSharp.Core
nuget Microsoft.NET.Test.Sdk
nuget System.CommandLine 2.0.0-beta1.20371.2
nuget System.Drawing.Common
Expand Down
Loading

0 comments on commit cc3182b

Please sign in to comment.