Skip to content

Commit c2411f9

Browse files
committed
Ensure Protobuf is available in build
1 parent 325d548 commit c2411f9

File tree

4 files changed

+52
-9
lines changed

4 files changed

+52
-9
lines changed

.pipelines/DSC-Official.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ extends:
321321
ob_restore_phase: true
322322
- pwsh: |
323323
apt update
324-
apt -y install musl-tools rpm dpkg build-essential
324+
apt -y install musl-tools rpm dpkg build-essential protobuf-compiler
325325
$header = "Bearer $(AzToken)"
326326
$env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header
327327
$env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token'
@@ -381,6 +381,7 @@ extends:
381381
apt -y install rpm
382382
apt -y install dpkg
383383
apt -y install build-essential
384+
apt install -y protobuf-compiler
384385
msrustup default stable-aarch64-unknown-linux-musl
385386
if ((openssl version -d) -match 'OPENSSLDIR: "(?<dir>.*?)"') {
386387
$env:OPENSSL_LIB_DIR = $matches['dir']

build.helpers.psm1

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,6 @@ function Install-NodeJS {
611611
}
612612
} elseif ($IsWindows) {
613613
if (Get-Command 'winget' -ErrorAction Ignore) {
614-
Write-Warning "WHY WHAT IS HAPPENING HERE"
615614
Write-Verbose -Verbose "Using winget to install Node.js"
616615
winget install OpenJS.NodeJS --accept-source-agreements --accept-package-agreements --source winget --silent
617616
} else {
@@ -627,6 +626,50 @@ function Install-NodeJS {
627626
}
628627
}
629628

629+
function Install-Protobuf {
630+
<#
631+
.SYNOPSIS
632+
Installs Protobuf for the protoc executable.
633+
#>
634+
635+
[cmdletbinding()]
636+
param()
637+
638+
process {
639+
if ((Get-Command 'protoc' -ErrorAction Ignore)) {
640+
Write-Verbose "Protobuf already installed."
641+
return
642+
}
643+
644+
Write-Verbose -Verbose "Protobuf not found, installing..."
645+
if ($IsMacOS) {
646+
if (Get-Command 'brew' -ErrorAction Ignore) {
647+
brew install protobuf
648+
} else {
649+
Write-Warning "Homebrew not found, please install Protobuf manually"
650+
}
651+
} elseif ($IsWindows) {
652+
if (Get-Command 'winget' -ErrorAction Ignore) {
653+
Write-Verbose -Verbose "Using winget to install Protobuf"
654+
winget install Google.Protobuf --accept-source-agreements --accept-package-agreements --source winget --silent
655+
} else {
656+
Write-Warning "winget not found, please install Protobuf manually"
657+
}
658+
} else {
659+
if (Get-Command 'apt' -ErrorAction Ignore) {
660+
Write-Verbose -Verbose "Using apt to install Protobuf"
661+
sudo apt install -y protobuf-compiler
662+
} else {
663+
Write-Warning "apt not found, please install Protobuf manually"
664+
}
665+
}
666+
667+
if ($LASTEXITCODE -ne 0) {
668+
throw "Failed to install Protobuf"
669+
}
670+
}
671+
}
672+
630673
function Install-PowerShellTestPrerequisite {
631674
[cmdletbinding()]
632675
param(

build.ps1

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,14 @@ process {
203203
}
204204

205205
if (-not ($SkipBuild -and $Test -and $ExcludeRustTests)) {
206-
# Install Node if needed
207206
Write-BuildProgress @progressParams -Status 'Ensuring Node.JS is available'
208207
Install-NodeJS @VerboseParam
209-
210-
# Ensure tree-sitter is installed
208+
211209
Write-BuildProgress @progressParams -Status 'Ensuring tree-sitter is available'
212210
Install-TreeSitter -UseCFS:$UseCFS @VerboseParam
211+
212+
Write-BuildProgress @progressParams -Status 'Ensuring Protobuf is available'
213+
Install-Protobuf @VerboseParam
213214
}
214215
}
215216

@@ -259,7 +260,7 @@ process {
259260
if ($Test) {
260261
$progressParams.Activity = 'Testing projects'
261262
Write-BuildProgress @progressParams
262-
263+
263264
if (-not $ExcludeRustTests) {
264265
$rustTestParams = @{
265266
Project = $BuildData.Projects
@@ -319,4 +320,4 @@ clean {
319320
}
320321

321322
Write-BuildProgress -Completed
322-
}
323+
}

dscbicep/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
99
tonic_prost_build::configure()
1010
.build_client(false)
1111
.file_descriptor_set_path(&descriptor_path)
12-
// TODO: Configure and commit the out_dir to avoid dependency on protoc
13-
// .out_dir(out_dir)
1412
.compile_protos(&["proto/bicep.proto"], &["proto"])?;
1513
Ok(())
1614
}

0 commit comments

Comments
 (0)