Skip to content

Commit

Permalink
added native compilation support
Browse files Browse the repository at this point in the history
  • Loading branch information
rasberry committed May 18, 2019
1 parent f608ee5 commit 4bceb51
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 17 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Parfait is a wrapper to create and manage par2 files so that recovery info can b
`dotnet run -p src -- -t .`

## Cleanup
find -H . -type d | grep -i "^./[^\.]*\.par2" | xargs -n1 -d '\n' trash
find -H . -type d | grep -i "\.par2$" | xargs -n1 -d '\n' trash

## TODO
* see if we can replace the par2 executable with https://github.com/heksesang/Parchive.NET
* add tests for file system premissions failures
* create directory
* delete file
Expand All @@ -58,4 +59,4 @@ find -H . -type d | grep -i "^./[^\.]*\.par2" | xargs -n1 -d '\n' trash
* add flag to turn off recreate (manual mode) and only verify
* maybe add input file with instructions for each file specified (re-create / restore / do nothing)
* compile using .net native
* https://docs.microsoft.com/en-us/dotnet/framework/net-native/
* https://docs.microsoft.com/en-us/dotnet/framework/net-native/
63 changes: 54 additions & 9 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ else
TARGET=$(toLower "$1")
fi

_getrid() {
if [[ "$OSTYPE" == "linux"* ]]; then
echo "linux-x64"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "osx-x64"
elif [[ "$OSTYPE" == "cygwin" ]]; then
echo "linux-x64"
elif [[ "$OSTYPE" == "msys" ]]; then
echo "win-x64"
elif [[ "$OSTYPE" == "win32" ]]; then
echo "win-x64"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo ""
else
echo ""
fi
}

test() {
dotnet test
}
Expand All @@ -23,25 +41,52 @@ release() {
_publishone() {
if [ -z "$1" ]; then echo "_publishone invalid rid"; exit 1; fi
if [ -z "$2" ]; then echo "_publishone invalid version"; exit 1; fi
if [ -z "$3" ]; then echo "_publishone framework"; exit 1; fi
# if [ -z "$3" ]; then echo "_publishone framework"; exit 1; fi

if [ ! -f "publish" ]; then mkdir "publish"; fi

dotnet publish -c Release --self-contained -r "$1" "src/Parfait.csproj"

list="/tmp/make.sh.tmp.txt"
find "./src/bin/Release/$3/$1/" -maxdepth 1 -type f > "$list"

# do a restore with RID
dotnet restore -r "$1" --force-evaluate

# build regular
outNormal = "bin/Normal/$1"
dotnet build -c Release -r "$1" -o "$outNormal" "src/Parfait.csproj"

# build standalone
outAlone = "bin/Alone/$1"
dotnet publish -c Release --self-contained -r "$1" -o "$outAlone" "src/Parfait.csproj"

# build native - TODO currently does not support cross-compiling
outNative="bin/Native/$1"
mv "src/Parfait.csproj" "src/Parfait.csproj.orig"
cp "src/Parfait.csproj.native" "src/Parfait.csproj"
dotnet publish -c Release -r "$1" -o "$outNative" "src/Parfait.csproj"
mv "src/Parfait.csproj.orig" "src/Parfait.csproj"

# package regular build
find "./src/$outNormal/" -maxdepth 1 -type f > "$list"
7z a -mx=9 -ms=on -i@"$list" "./publish/$1-$2.7z"
find "./src/bin/Release/$3/$1/publish/" -maxdepth 1 -type f > "$list"

# package standalone build
find "./src/$outAlone/" -maxdepth 1 -type f > "$list"
7z a -mx=9 -ms=on -i@"$list" "./publish/$1-$2-standalone.7z"
rm "$list"

# package native build
find "./src/$outNative/" -maxdepth 1 -type f > "$list"
7z a -mx=9 -ms=on -i@"$list" "./publish/$1-$2-native.7z"

rm "$list"
}
publish() {
# https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
_publishone "win-x64" "1.0.0" "netcoreapp2.0"
_publishone "linux-x64" "1.0.0" "netcoreapp2.0"
_publishone "osx-x64" "1.0.0" "netcoreapp2.0"
rid="$(_getrid)"
if [ -n "$rid" ]; then
_publishone "$(_getrid)" "0.1.0" "netcoreapp2.0"
else
echo "RID '$OSTYPE' not recognized"
fi
}

2>/dev/null $TARGET || (echo "Target \"$TARGET\" doesn't exist"; exit 1)
9 changes: 9 additions & 0 deletions nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion src/ParHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static int Exec(string program, string args, out string stdout,out string stderr
si.CreateNoWindow = true; //don't diplay a window

proc.StartInfo = si;
proc.PriorityClass = ProcessPriorityClass.Idle;
// proc.PriorityClass = ProcessPriorityClass.Idle;
proc.Start();
stdout = proc.StandardOutput.ReadToEnd(); //The output result
stderr = proc.StandardError.ReadToEnd();
Expand Down
4 changes: 0 additions & 4 deletions src/Parfait.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="newtonsoft.json" Version="11.0.2" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions src/Parfait.csproj.native
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-*" />
</ItemGroup>

<PropertyGroup>
<RootAllApplicationAssemblies>false</RootAllApplicationAssemblies>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
<IlcGenerateCompleteTypeMetadata>false</IlcGenerateCompleteTypeMetadata>
<!--<IlcDisableReflection>true</IlcDisableReflection>-->
<IlcOptimizationPreference>Size</IlcOptimizationPreference>
<IlcFoldIdenticalMethodBodies>true</IlcFoldIdenticalMethodBodies>
</PropertyGroup>

</Project>
1 change: 0 additions & 1 deletion test/Parfait.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down

0 comments on commit 4bceb51

Please sign in to comment.