rive-app / rive-flutter

Flutter runtime for Rive
https://rive.app
MIT License
1.2k stars 188 forks source link

Codemagic Windows Build #394

Open AndreiMisiukevich opened 3 months ago

AndreiMisiukevich commented 3 months ago

Description

Could you please describe how to build a Windows app with Codemagic? It seems it's impossible now due to CLang constraint

Steps To Reproduce

Steps to reproduce the behavior:

  1. Create a windows app with latest rive package
  2. Try to build the app with Codemagic

Expected behavior

App builds successfully

Device & Versions (please complete the following information)

Additional context

Related: https://github.com/rive-app/rive-flutter/issues/308

eivihnd commented 3 months ago

While awaiting Codemagic to improve its Windows support, this is how I currently have managed to get my Flutter app with Rive to build in Codemagic:

Prepare_machine.ps1

echo "Downloading Visual Studio Community Installer..."
$installerDir = 'C:\Users\builder\clone\vs_installer'
$directory = './vs_installer'
if (-Not (Test-Path $directory)) {
  New-Item -ItemType Directory -Path $directory
}
# Start the job to download the installer
Start-Job -Name DownloadVS -ArgumentList $installerDir -ScriptBlock {
  param ($installerDir)
  Invoke-WebRequest 'https://aka.ms/vs/17/release/vs_community.exe' -OutFile "$installerDir/vs_community.exe"
}

# Wait for the job to complete
Wait-Job -Name DownloadVS

# Check the job result
$job = Get-Job -Name DownloadVS
$jobResult = Receive-Job -Job $job
Remove-Job -Job $job

if ($jobResult.Exception -eq $null) {
    echo "Download successful"
} else {
    echo "Download failed with the following error: $($jobResult.Exception.Message)"
    exit 1
}

# -------------------------------------------
echo "Find the latest version of Visual Studio installed ..."
$latestVS = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath

# Path to vswhere.exe
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"

# Check if vswhere.exe exists
if (-Not (Test-Path $vswherePath)) {
    Write-Error "vswhere.exe not found. Please ensure Visual Studio Installer is installed."
    exit 1
}

# Run vswhere to get the product display version of the latest Visual Studio
$latestVSVersion = & $vswherePath -latest -property catalog_productDisplayVersion

# Output the version number
if ($latestVSVersion) {
    Write-Output "VS version: $latestVS ($latestVSVersion)"
} else {
    Write-Output "No Visual Studio installation found."
}

# -------------------------------------------
echo "Set the VSINSTALLDIR environment variable to let Flutter use VS2022..."
[Environment]::SetEnvironmentVariable("VSINSTALLDIR", $latestVS, [EnvironmentVariableTarget]::User)

echo "Output the environment variable to confirm ..."
$envVSInstallDir = [Environment]::GetEnvironmentVariable("VSINSTALLDIR", [EnvironmentVariableTarget]::User)
Write-Output "VSINSTALLDIR is set to: $envVSInstallDir"

# -------------------------------------------
# echo "Updating Visual Studio..."
# $updateProcess = Start-Process -Wait -FilePath "$installerDir\vs_community.exe" -ArgumentList "update --passive --norestart --installpath ""C:\Program Files\Microsoft Visual Studio\2022\Community""" -PassThru;
# Write-Output $updateProcess.ExitCode;

# # Run vswhere to get the product display version of the latest Visual Studio
# $latestVSVersion = & $vswherePath -latest -property catalog_productDisplayVersion

# # Output the version number
# if ($latestVSVersion) {
#     Write-Output "VS version after update: $latestVS ($latestVSVersion)"
# } else {
#     Write-Output "No Visual Studio installation found."
# }

# -------------------------------------------
echo "Installing necessary VS components..."
# Components to be installed
$components = @(

)

$componentsString = $components -join " "

$arguments = @(
    "modify",
    "--productId", "Microsoft.VisualStudio.Product.Community",
    "--channelId", "VisualStudio.17.Release",
    "--add","Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset",
    "--add","Microsoft.VisualStudio.Component.VC.Llvm.Clang",
    "--add","Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Llvm.Clang",
    "--add","Microsoft.VisualStudio.Component.VC.ATL",
    "--add","Microsoft.VisualStudio.Component.VC.ATL.Spectre",
    "--add","Microsoft.VisualStudio.Component.VC.ATLMFC.Spectre",
    "--passive",
    "--wait"
)

# Start the process
$logFile = "C:\Users\builder\clone\vs_installer\vs_installer.log"
$errorLogFile = "C:\Users\builder\clone\vs_installer\vs_installer_error.log"

echo "Args: $arguments"

$componentsProcess = Start-Process -FilePath "$directory/vs_community.exe" -ArgumentList $arguments -NoNewWindow -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -Wait -PassThru

Write-Output $componentsProcess.ExitCode;
# Display the log file content
Get-Content -Path $logFile -Raw | Write-Output
Get-Content -Path $errorLogFile -Raw | Write-Output

Codemagic.yaml (insert this in the script section of your windows build scripts)

- name: Install VS Code and Clang Toolset
   script: |
      .\.codemagic\prepare_machine.ps1
AndreiMisiukevich commented 2 months ago

Thanks @eivihnd it works very well But unfortunately, it increases build time by 4 mins (That is not critical, maybe... but every build now costs extra 0.184$)