Linker optimizations (#633)

* Initial linker optimizations

* Fix Windows build
This commit is contained in:
Łukasz Domeradzki 2017-08-31 07:30:09 +02:00 committed by GitHub
parent bf89ba7638
commit 197539f353
5 changed files with 41 additions and 14 deletions

View file

@ -36,7 +36,7 @@ script:
publish() {
if [ "$1" = 'generic' ]; then
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" --no-restore /nologo /p:LinkDuringPublish=false
else
dotnet publish ArchiSteamFarm -c "$CONFIGURATION" -o "out/${1}" -r "$1" --no-restore /nologo
fi

View file

@ -19,8 +19,6 @@
<PackageIconUrl>https://github.com/JustArchi/ArchiSteamFarm/raw/master/resources/ASF.ico</PackageIconUrl>
<RepositoryType>Git</RepositoryType>
<NoWarn />
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
<ServerGarbageCollection>false</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>
@ -28,12 +26,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HtmlAgilityPack" Version="1.5.2-beta6" />
<PackageReference Include="Humanizer" Version="2.2.0" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0-beta1" />
<PackageReference Include="ILLink.Tasks" Version="0.1.4-preview-906439" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="NLog" Version="5.0.0-beta09" />
<PackageReference Include="SteamKit2" Version="2.0.0-Alpha7" />

View file

@ -26,7 +26,6 @@ using System;
using System.IO;
using System.Runtime.InteropServices;
using ArchiSteamFarm.Localization;
using Mono.Unix;
namespace ArchiSteamFarm {
internal static class OS {
@ -47,12 +46,13 @@ namespace ArchiSteamFarm {
}
internal static void UnixSetFileAccessExecutable(string path) {
if (!File.Exists(path) || !UnixFileSystemInfo.TryGetFileSystemEntry(path, out UnixFileSystemInfo entry)) {
if (!File.Exists(path)) {
return;
}
if (!entry.FileAccessPermissions.HasFlag(FileAccessPermissions.UserExecute)) {
entry.FileAccessPermissions = entry.FileAccessPermissions | FileAccessPermissions.UserExecute;
// Chmod() returns 0 on success, -1 on failure
if (NativeMethods.Chmod(path, (int) NativeMethods.UnixExecutePermission) != 0) {
ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningFailedWithError, Marshal.GetLastWin32Error()));
}
}
@ -76,7 +76,7 @@ namespace ArchiSteamFarm {
// This function calls unmanaged API in order to tell Windows OS that it should not enter sleep state while the program is running
// If user wishes to enter sleep mode, then he should use ShutdownOnFarmingFinished or manage ASF process with third-party tool or script
// More info: https://msdn.microsoft.com/library/windows/desktop/aa373208(v=vs.85).aspx
NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.EExecutionState.AwayModeRequired | NativeMethods.EExecutionState.Continuous | NativeMethods.EExecutionState.SystemRequired);
NativeMethods.EExecutionState result = NativeMethods.SetThreadExecutionState(NativeMethods.AwakeExecutionState);
// SetThreadExecutionState() returns NULL on failure, which is mapped to 0 (EExecutionState.Error) in our case
if (result == NativeMethods.EExecutionState.Error) {
@ -85,19 +85,24 @@ namespace ArchiSteamFarm {
}
private static class NativeMethods {
internal const EExecutionState AwakeExecutionState = EExecutionState.SystemRequired | EExecutionState.AwayModeRequired | EExecutionState.Continuous;
internal const uint EnableQuickEditMode = 0x0040;
internal const sbyte StandardInputHandle = -10;
internal const EUnixPermission UnixExecutePermission = EUnixPermission.UserRead | EUnixPermission.UserWrite | EUnixPermission.UserExecute | EUnixPermission.GroupRead | EUnixPermission.GroupExecute | EUnixPermission.OtherRead | EUnixPermission.OtherExecute;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
[DllImport("libc", EntryPoint = "chmod", SetLastError = true)]
internal static extern int Chmod(string path, int mode);
[DllImport("kernel32.dll")]
internal static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
[DllImport("kernel32.dll")]
internal static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
[DllImport("kernel32.dll")]
internal static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
[DllImport("kernel32.dll")]
internal static extern EExecutionState SetThreadExecutionState(EExecutionState executionState);
[Flags]
@ -107,6 +112,22 @@ namespace ArchiSteamFarm {
AwayModeRequired = 0x00000040,
Continuous = 0x80000000
}
[Flags]
internal enum EUnixPermission {
OtherExecute = 0x1,
OtherRead = 0x4,
GroupExecute = 0x8,
GroupRead = 0x20,
UserExecute = 0x40,
UserWrite = 0x80,
UserRead = 0x100
/*
OtherWrite = 0x2
GroupWrite = 0x10
*/
}
}
}
}

View file

@ -62,7 +62,7 @@ after_test:
Set-Location -Path "$env:APPVEYOR_BUILD_FOLDER"
if ($RUNTIME -eq 'generic') {
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" --no-restore /nologo
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" --no-restore /nologo /p:LinkDuringPublish=false
} else {
dotnet publish ArchiSteamFarm -c "$env:CONFIGURATION" -o "out\$RUNTIME" -r "$RUNTIME" --no-restore /nologo
}

6
nuget.config Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
</packageSources>
</configuration>