Skip to content

Commit

Permalink
Add specific platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
xBaank committed Aug 13, 2024
1 parent cab8764 commit ef003d6
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ bld/
## sqlite
*.db

## libs
*.so
*.dll
*.dylib

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
Expand Down
36 changes: 34 additions & 2 deletions Console/Console.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<UseAppHost>false</UseAppHost>
<UseAppHost>true</UseAppHost>
<TrimMode>full</TrimMode>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -18,7 +19,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="PortAudioSharp2" Version="1.0.4" />
<PackageReference Include="PortAudioSharp" Version="0.3.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="Terminal.Gui" Version="2.0.0-prealpha.216" />
Expand All @@ -27,4 +28,35 @@
<ItemGroup>
<InternalsVisibleTo Include="Tests" />
</ItemGroup>

<ItemGroup>
<TrimmerRootAssembly Include="CliFx" />
<TrimmerRootAssembly Include="Microsoft.EntityFrameworkCore.Sqlite" />
</ItemGroup>

<PropertyGroup>
<PortAudioPlatform>$(RuntimeIdentifier)</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">win-arm64</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">win-x86</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Windows')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">win-x64</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">linux-arm64</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">linux-x86</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('Linux')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">linux-x64</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('OSX')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">osx-arm64</PortAudioPlatform>
<PortAudioPlatform Condition="'$(PortAudioPlatform)' == '' AND $([MSBuild]::IsOsPlatform('OSX')) AND '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">osx-x64</PortAudioPlatform>
<PortAudioFileName Condition="$(PortAudioPlatform.StartsWith('win-'))">portaudio.dll</PortAudioFileName>
<PortAudioFileName Condition="$(PortAudioPlatform.StartsWith('linux-'))">libportaudio.so</PortAudioFileName>
<PortAudioFileName Condition="'$(PortAudioFileName)' == ''">libportaudio.dylib</PortAudioFileName>
</PropertyGroup>

<Target Name="Download PortAudio before build" BeforeTargets="PreBuildEvent">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadPortAudioBin.ps1&quot; -Platform $(PortAudioPlatform) -OutputPath &quot;$(ProjectDir)/$(PortAudioFileName)&quot;" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/$(PortAudioFileName)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
</Target>

<Target Name="Download PortAudio before publish" BeforeTargets="PrepareForPublish">
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)/DownloadPortAudioBin.ps1&quot; -Platform $(PortAudioPlatform) -OutputPath &quot;$(ProjectDir)/$(PortAudioFileName)&quot;" LogStandardErrorAsError="true" />
<Copy SourceFiles="$(ProjectDir)/$(PortAudioFileName)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
</Target>

</Project>
42 changes: 42 additions & 0 deletions Console/DownloadPortAudioBin.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
param (
[string]$platform,
[string]$outputPath
)

$ErrorActionPreference = "Stop"

# Normalize platform identifier
$platform = $platform.ToLower().Replace("win-", "windows-")

# Check if already exists
if (Test-Path $outputPath) {
Write-Host "Skipped downloading Portaudio, file already exists."
exit
}

# Download the archive
Write-Host "Downloading Portaudio..."
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$http = New-Object System.Net.WebClient
try {
$http.DownloadFile("https://github.com/xBaank/PortAudioBin/releases/download/19.7/portaudio-$platform.zip", "$outputPath.zip")
} finally {
$http.Dispose()
}

try {
# Extract FFmpeg
Add-Type -Assembly System.IO.Compression.FileSystem
$zip = [IO.Compression.ZipFile]::OpenRead("$outputPath.zip")
try {
$fileName = If ($platform.Contains("windows-")) { "bin/portaudio.dll" } ElseIf ($platform.Contains("linux-")) { "lib/libportaudio.so" } Else { "lib/libportaudio.dylib" }
[IO.Compression.ZipFileExtensions]::ExtractToFile($zip.GetEntry($fileName), $outputPath)
} finally {
$zip.Dispose()
}

Write-Host "Done downloading Portaudio."
} finally {
# Clean up
Remove-Item "$outputPath.zip" -Force
}

0 comments on commit ef003d6

Please sign in to comment.