Skip to content

Commit

Permalink
Redo launcher csproj and action to use framework dependent builds
Browse files Browse the repository at this point in the history
This also includes package updates across the entire solution, which shouldn't matter at this stage on this branch.
  • Loading branch information
SignatureBeef committed Jul 27, 2022
1 parent 49a2dce commit 578df18
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-otapi3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ jobs:
- name: Produce build
run: |
cd TShockLauncher
dotnet publish -r ${{ matrix.arch }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained true
dotnet publish -r ${{ matrix.arch }} -f net6.0 -c Release -p:PublishSingleFile=true --self-contained false
- name: Chmod scripts
if: ${{ matrix.arch != 'win-x64' }}
run: |
chmod +x TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/TShock.sh
chmod +x TShockLauncher/bin/Release/net6.0/${{ matrix.arch }}/publish/TShock.Server
# preserve file perms: https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files
- name: Archive artifact
Expand Down
4 changes: 2 additions & 2 deletions TShockAPI/TShockAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.30" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions TShockLauncher.Tests/TShockLauncher.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 0 additions & 2 deletions TShockLauncher/TShock.sh

This file was deleted.

77 changes: 14 additions & 63 deletions TShockLauncher/TShockLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,89 +5,40 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName Condition="'$(RuntimeIdentifier)' == 'win-x64' Or '$(RuntimeIdentifier)' == ''">TShock</AssemblyName>
<AssemblyName Condition="'$(RuntimeIdentifier)' != 'win-x64' And '$(RuntimeIdentifier)' != ''">TShock.Run</AssemblyName>
<AssemblyName>TShock.Server</AssemblyName>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<DebugType>embedded</DebugType>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <!-- needed for sqlite native libs -->
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TerrariaServerAPI\TerrariaServerAPI\TerrariaServerAPI.csproj" ExcludeFromSingleFile="true" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" Condition="'$(PublishSingleFile)' == 'true'" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ReferenceOutputAssembly="false" Condition="'$(PublishSingleFile)' != 'true'" />
<ProjectReference Include="..\TShockAPI\TShockAPI.csproj" ExcludeFromSingleFile="true" ReferenceOutputAssembly="false" /> <!-- allow api to rebuilt with this project, so ServerPlugins are refreshed -->
<Reference Include="HttpServer" ExcludeFromSingleFile="true">
<HintPath>..\prebuilts\HttpServer.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<!-- match tshocks dependencies so that publishing outputs all files to ./bin -->
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.28" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.3" />
<PackageReference Include="MySql.Data" Version="8.0.30" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
<PackageReference Include="ModFramework" Version="1.0.40-alpha" /> <!-- temporary until otapi's nuget package describes the right version. oops. -->
</ItemGroup>

<Target Name="MoveTShockDebug" AfterTargets="FinalCleanup;PostBuildEvent">
<ItemGroup>
<TShockPluginFilesDebug Include="$(TargetDir)/TShockAPI*" />
</ItemGroup>
<Move SourceFiles="@(TShockPluginFilesDebug)" DestinationFolder="$(TargetDir)ServerPlugins" ContinueOnError="true" />
</Target>
<Target Name="MoveTShockPublish" AfterTargets="Publish">

<Target Name="CreateServerPlugins" AfterTargets="PostBuildEvent;Publish">
<MakeDir Directories="$(OutDir)ServerPlugins" />
<MakeDir Directories="$(PublishDir)ServerPlugins" />
<ItemGroup>
<TShockPluginFilesPublish Include="$(PublishDir)/TShockAPI*" />
<TShockPluginFilesForPublish Include="$(ProjectDir)../TShockAPI/bin/$(Configuration)/$(TargetFramework)/TShockAPI*" Condition="'$(PublishSingleFile)' != 'true'" />
<ApiFiles Include="$(ProjectDir)../TShockAPI/bin/$(Configuration)/$(TargetFramework)/TShockAPI*" />
</ItemGroup>
<Move SourceFiles="@(TShockPluginFilesPublish)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" />
<Copy SourceFiles="@(TShockPluginFilesForPublish)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" Condition="'$(PublishSingleFile)' != 'true'" />
<Copy SourceFiles="@(ApiFiles)" DestinationFolder="$(OutDir)ServerPlugins" ContinueOnError="true" />
<Copy SourceFiles="@(ApiFiles)" DestinationFolder="$(PublishDir)ServerPlugins" ContinueOnError="true" />
</Target>

<Target Name="MoveBin" AfterTargets="Publish">
<ItemGroup>
<MoveBinaries Include="$(PublishDir)*" Exclude="$(PublishDir)\TShock.exe;$(PublishDir)\TShockAPI*" />
<MoveBinaries Include="$(PublishDir)*" Exclude="$(PublishDir)\TShock.Server*" />
</ItemGroup>
<Move SourceFiles="@(MoveBinaries)" DestinationFolder="$(PublishDir)bin" ContinueOnError="true" />
</Target>

<UsingTask TaskName="PatchAppHost" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<HostExe ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
/*
This is a patch to allow self contained apps to run from the root while having the modules in a ./bin folder.
https://github.com/dotnet/sdk/issues/10366

The script replaces the ./TShock.dll with ./bin/TShock.dll
alternates: dnSpy(does this method), NetCoreBeauty
*/
var find = Encoding.UTF8.GetBytes("TShock.dll\0");
var replace = Encoding.UTF8.GetBytes("bin" + Path.DirectorySeparatorChar + "TShock.dll\0");
var contents = File.ReadAllBytes(HostExe);

var matches = 0;
var offset = Array.FindIndex(contents, (b) =&gt; {
matches = (b == find[matches]) ? matches + 1 : 0;
return matches == find.Length;
});
if (offset &gt; -1) offset -= find.Length - 1;

var x = 0;
Array.ForEach(replace, _ =&gt; { contents[offset + x] = replace[x++]; });

File.WriteAllBytes(HostExe, contents);
</Code>
</Task>
</UsingTask>

<Target Name="PatchAppHostAfterPublish" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<PatchAppHost HostExe="$(PublishDir)TShock.exe" />
<Message Text="Patched TShock.exe host for ./bin redirect" Importance="High" />
</Target>
<Target Name="CreateScriptAfterPublish" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' != 'win-x64'">
<Copy SourceFiles="$(ProjectDir)TShock.sh" DestinationFolder="$(PublishDir)" />
<Message Text="Run the launcher with chmod +x TShock.sh &amp;&amp; ./TShock.sh" Importance="High" />
</Target>
</Project>
5 changes: 0 additions & 5 deletions TShockLauncher/runtimeconfig.template.json

This file was deleted.

2 changes: 1 addition & 1 deletion TerrariaServerAPI

0 comments on commit 578df18

Please sign in to comment.