Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codemagic Windows Build #394

Open
AndreiMisiukevich opened this issue Jun 4, 2024 · 2 comments
Open

Codemagic Windows Build #394

AndreiMisiukevich opened this issue Jun 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@AndreiMisiukevich
Copy link

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)

  • Device: Codemagic Windows machine
  • OS: Windows
  • Flutter Version: latest

Additional context

Related: #308

@AndreiMisiukevich AndreiMisiukevich added the bug Something isn't working label Jun 4, 2024
@eivihnd
Copy link

eivihnd commented Jul 1, 2024

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
Copy link
Author

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$)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants