Skip to content

Commit

Permalink
Found a hacky way to compile for Win32
Browse files Browse the repository at this point in the history
  • Loading branch information
lelegard committed Sep 5, 2021
1 parent f35ef6a commit 66941a0
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 94 deletions.
4 changes: 2 additions & 2 deletions URL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ https://code.videolan.org/rist/librist.git

# If a temporary alternate URL is needed, for instance waiting for a
# merge request to be merged, other URL's can be added below. Only
# last (uncommented) URL is used.
# https://code.videolan.org/lelegard/librist.git
# the last (uncommented) URL is used.
https://code.videolan.org/lelegard/librist.git
2 changes: 1 addition & 1 deletion deb/librist-dev.control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: librist-dev
Source: rist
Version: {{VERSION}}
Maintainer: Thierry Lelegard <[email protected]>
Maintainer: Unspecified <[email protected]>
Architecture: {{ARCH}}
Section: free/video
Priority: optional
Expand Down
2 changes: 1 addition & 1 deletion deb/librist.control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: librist
Source: rist
Version: {{VERSION}}
Maintainer: Thierry Lelegard <[email protected]>
Maintainer: Unspecified <[email protected]>
Architecture: {{ARCH}}
Section: free/video
Priority: optional
Expand Down
2 changes: 1 addition & 1 deletion deb/rist.control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rist
Source: rist
Version: {{VERSION}}
Maintainer: Thierry Lelegard <[email protected]>
Maintainer: Unspecified <[email protected]>
Architecture: {{ARCH}}
Section: free/video
Priority: optional
Expand Down
79 changes: 44 additions & 35 deletions win/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ $RootDir = (Split-Path -Parent $PSScriptRoot)
$InstallerDir = "$RootDir\installers"
$BuildDir = "$RootDir\build"
$RepoDir = "$BuildDir\librist"
$PreInstallDir = "$BuildDir\install"

# Cleanup when required.
if ($Clean) {
Expand All @@ -106,7 +105,6 @@ if ($Clean) {

# Create local build directories.
[void] (New-Item -Path $BuildDir -ItemType Directory -Force)
[void] (New-Item -Path $PreInstallDir -ItemType Directory -Force)
[void] (New-Item -Path $InstallerDir -ItemType Directory -Force)

# Locate NSIS, the Nullsoft Scriptable Installation System.
Expand Down Expand Up @@ -180,58 +178,69 @@ Write-Output "RIST version is $Version, Windows version info is $VersionInfo"
# Build only if necessary.
if (-not $NoBuild) {

Cleanup-Build

# Get local architecture.
if ([System.IntPtr]::Size -eq 4) {
$LocalArch = "Win32"
$OtherArch = "x64"
$CrossScript = "vcvarsx86_amd64.bat"
}
else {
$LocalArch = "x64"
$OtherArch = "Win32"
$CrossScript = "vcvarsamd64_x86.bat"
}

# Build all build scripts using meson for local architecture.
Cleanup-Build
# Build using meson for local architecture.
meson setup --backend vs2019 --buildtype release --default-library both $BuildDir\Release-${LocalArch} $RepoDir
meson setup --backend vs2019 --buildtype debug --default-library both $BuildDir\Debug-${LocalArch} $RepoDir

meson compile -C $BuildDir\Release-${LocalArch}
meson compile -C $BuildDir\Debug-${LocalArch}

# Currently, there is no way to build for the "other" architecture with meson.
# See: https://code.videolan.org/rist/librist/-/issues/123

# Manually craft the build environment for the "other" architecture.
#@@@ foreach ($Conf in @("Release", "Debug")) {
#@@@ $local = "$BuildDir\${Conf}-${LocalArch}"
#@@@ $other = "$BuildDir\${Conf}-${OtherArch}"
#@@@ # Copy-Item -Force -Recurse $BuildDir\${Conf}-${LocalArch} $BuildDir\${Conf}-${OtherArch}
#@@@ # Get-ChildItem -Recurse -Name $BuildDir\${Conf}-${OtherArch} | ForEach-Object {
#@@@ Get-ChildItem -Recurse -Name $local | ForEach-Object {
#@@@ $name = $_
#@@@ if (Test-Path "$local\$name" -PathType Container) {
#@@@ Write-Output "===> creating $other\$name"
#@@@ [void] (New-Item -Path "$other\$name" -ItemType Directory -Force)
#@@@ }
#@@@ else {
#@@@ (Get-Content -Raw "$local\$name") -replace "$LocalArch","$OtherArch" | Set-Content -Force "$other\$name"
#@@@ # $file = "$BuildDir\${Conf}-${OtherArch}\$_"
#@@@ # (Get-Content -Raw ${file}) -replace "$LocalArch","$OtherArch" | Set-Content -Force "${file}.new"
#@@@ # Move-Item -Force "${file}.new" ${file}
#@@@ }
#@@@ }
#@@@ }

# Build librist in all configurations.
foreach ($Conf in @("Release", "Debug")) {
meson compile -C $BuildDir\${Conf}-${LocalArch}
# So, we are going the hacky way. Just pretend we are cross-compiling for
# the other architecture using the CMD script from VisualStudio, get the
# environment variables from the CMD command, temporarily set them for meson.
# It seems to work by magic...

# Search the CMD script from VisualStudio.
$Script = (Get-ChildItem -Recurse -Path "C:\Program Files*\Microsoft Visual Studio" -Include $CrossScript | Select-Object -First 1).FullName
if (-not $Script) {
Exit-Script "$CrossScript not found in Visual Studio"
}
}

# Only when using single architecture.
$ArchName = "-" + ($LocalArch -replace "x64","Win64")
# Run the CMD script, get all environment variable, set modified ones.
$PreviousEnv = @{}
cmd /Q /a /d /c "`"$Script`" & set" | Select-string "^[a-zA-Z0-9_]*=" | ForEach-Object {
$s = $_ -split "=",2
$name = $s[0]
$value = $s[1]
$previous = (Get-Item env:$name -ErrorAction SilentlyContinue).Value
if ($value -ne $previous) {
$PreviousEnv[$name] = $previous
Set-Item env:$name $value
}
}

# Build using the other architecture.
meson setup --backend vs2019 --buildtype release --default-library both $BuildDir\Release-${OtherArch} $RepoDir
meson setup --backend vs2019 --buildtype debug --default-library both $BuildDir\Debug-${OtherArch} $RepoDir

meson compile -C $BuildDir\Release-${OtherArch}
meson compile -C $BuildDir\Debug-${OtherArch}

# Restore previous environment variables.
$PreviousEnv.GetEnumerator() | ForEach-Object {
$name = $_.Name
Set-Item env:$name $_.Value
}
}

# Build the binary installer.
# Remove /DArch when we can build 32 and 64-bit versions at the same time.
Write-Output "Building installer ..."
& $NSIS /V2 `
/DProductName=librist ` /DVersion=$Version ` /DVersionInfo=$VersionInfo ` /DOutputName=librist${ArchName}-${Version} ` /DArch=$LocalArch ` /DScriptDir=$ScriptDir ` /DRepoDir=$RepoDir ` /DBuildDir=$BuildDir ` /DInstallerDir=$InstallerDir ` "$ScriptDir\librist.nsi"
/DProductName=librist ` /DVersion=$Version ` /DVersionInfo=$VersionInfo ` /DScriptDir=$ScriptDir ` /DRepoDir=$RepoDir ` /DBuildDir=$BuildDir ` /DInstallerDir=$InstallerDir ` "$ScriptDir\librist.nsi"

Exit-Script -NoPause:$NoPause
Expand Down
5 changes: 0 additions & 5 deletions win/cross-win32.txt

This file was deleted.

5 changes: 0 additions & 5 deletions win/cross-win64.txt

This file was deleted.

2 changes: 1 addition & 1 deletion win/librist.props → win/librist-common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Visual Studio or MSBuild property file to use RIST static library -->
<!-- Visual Studio or MSBuild common property file to use RIST library -->

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Expand Down
2 changes: 1 addition & 1 deletion win/librist-dll.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PropertyGroup Label="UserMacros">
<RistLibrary>librist.lib</RistLibrary>
</PropertyGroup>
<Import Project="$(LIBRIST)\librist.props"/>
<Import Project="$(LIBRIST)\librist-common.props"/>
<Target Name="AfterBuild">
<Copy SourceFiles="$(LIBRIST)\lib\$(Configuration)-$(RistPlatform)\librist.dll" DestinationFolder="$(OutDir)" />
</Target>
Expand Down
2 changes: 1 addition & 1 deletion win/librist-static.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
<PropertyGroup Label="UserMacros">
<RistLibrary>librist.a</RistLibrary>
</PropertyGroup>
<Import Project="$(LIBRIST)\librist.props"/>
<Import Project="$(LIBRIST)\librist-common.props"/>
</Project>
56 changes: 15 additions & 41 deletions win/librist.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ VIAddVersionKey FileVersion "${VersionInfo}"
VIAddVersionKey FileDescription "RIST Installer"

; Name of binary installer file.
OutFile "${InstallerDir}\${OutputName}.exe"
OutFile "${InstallerDir}\${ProductName}-${Version}.exe"

; Generate a Unicode installer (default is ANSI).
Unicode true
Expand Down Expand Up @@ -120,26 +120,21 @@ Section "Install"
; Visual Studio property files.
SetOutPath "$INSTDIR"
File /oname=COPYING.txt "${RepoDir}\COPYING"
File "${ScriptDir}\librist.props"
File "${ScriptDir}\librist-common.props"
File "${ScriptDir}\librist-dll.props"
File "${ScriptDir}\librist-static.props"
Delete "${ScriptDir}\librist.props"

; Header files.
CreateDirectory "$INSTDIR\include"
CreateDirectory "$INSTDIR\include\librist"
SetOutPath "$INSTDIR\include\librist"
File "${RepoDir}\include\librist\*.h"

; Libraries and tools.
CreateDirectory "$INSTDIR\lib"
CreateDirectory "$INSTDIR\bin"

!ifndef Arch
; Multiple architectures.
SetOutPath "$INSTDIR\include\librist"
File "${BuildDir}\Release-x64\include\librist\*.h"
File "${BuildDir}\Release-x64\include\vcs_version.h"

; Libraries.
CreateDirectory "$INSTDIR\lib"
CreateDirectory "$INSTDIR\lib\Release-x64"
SetOutPath "$INSTDIR\lib\Release-x64"
File "${BuildDir}\Release-x64\librist.dll"
Expand All @@ -164,37 +159,14 @@ Section "Install"
File "${BuildDir}\Debug-Win32\librist.lib"
File "${BuildDir}\Debug-Win32\librist.a"

; Tools.
CreateDirectory "$INSTDIR\bin"
SetOutPath "$INSTDIR\bin"
File "${BuildDir}\Release-x64\librist.dll"
File "${BuildDir}\Release-x64\tools\rist2rist.exe"
File "${BuildDir}\Release-x64\tools\ristreceiver.exe"
File "${BuildDir}\Release-x64\tools\ristsender.exe"
File "${BuildDir}\Release-x64\tools\ristsrppasswd.exe"
!else
; Single architecture.
SetOutPath "$INSTDIR\include\librist"
File "${BuildDir}\Release-${Arch}\include\librist\*.h"
File "${BuildDir}\Release-${Arch}\include\vcs_version.h"

CreateDirectory "$INSTDIR\lib\Release-${Arch}"
SetOutPath "$INSTDIR\lib\Release-${Arch}"
File "${BuildDir}\Release-${Arch}\librist.dll"
File "${BuildDir}\Release-${Arch}\librist.lib"
File "${BuildDir}\Release-${Arch}\librist.a"

CreateDirectory "$INSTDIR\lib\Debug-${Arch}"
SetOutPath "$INSTDIR\lib\Debug-${Arch}"
File "${BuildDir}\Debug-${Arch}\librist.dll"
File "${BuildDir}\Debug-${Arch}\librist.lib"
File "${BuildDir}\Debug-${Arch}\librist.a"

SetOutPath "$INSTDIR\bin"
File "${BuildDir}\Release-${Arch}\librist.dll"
File "${BuildDir}\Release-${Arch}\tools\rist2rist.exe"
File "${BuildDir}\Release-${Arch}\tools\ristreceiver.exe"
File "${BuildDir}\Release-${Arch}\tools\ristsender.exe"
File "${BuildDir}\Release-${Arch}\tools\ristsrppasswd.exe"
!endif
File "${BuildDir}\Release-Win32\librist.dll"
File "${BuildDir}\Release-Win32\tools\rist2rist.exe"
File "${BuildDir}\Release-Win32\tools\ristreceiver.exe"
File "${BuildDir}\Release-Win32\tools\ristsender.exe"
File "${BuildDir}\Release-Win32\tools\ristsrppasswd.exe"

; Add an environment variable to installation root.
WriteRegStr HKLM ${EnvironmentKey} "LIBRIST" "$INSTDIR"
Expand All @@ -207,6 +179,8 @@ Section "Install"

; Declare uninstaller in "Add/Remove Software" control panel
WriteRegStr HKLM "${UninstallKey}" "DisplayName" "${ProductName}"
WriteRegStr HKLM "${UninstallKey}" "Publisher" "VideoLAN and librist"
WriteRegStr HKLM "${UninstallKey}" "URLInfoAbout" "https://code.videolan.org/rist/librist"
WriteRegStr HKLM "${UninstallKey}" "DisplayVersion" "${Version}"
WriteRegStr HKLM "${UninstallKey}" "DisplayIcon" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "${UninstallKey}" "UninstallString" "$INSTDIR\Uninstall.exe"
Expand Down Expand Up @@ -240,7 +214,7 @@ Section "Uninstall"
RMDir /r "$0\include"
RMDir /r "$0\bin"
RMDir /r "$0\lib"
Delete "$0\librist.props"
Delete "$0\librist-common.props"
Delete "$0\librist-dll.props"
Delete "$0\librist-static.props"
Delete "$0\COPYING.txt"
Expand Down

0 comments on commit 66941a0

Please sign in to comment.