Skip to content

Commit

Permalink
CI/CD: Use a GitHub-hosted copy of nasm instead of downloading it fro…
Browse files Browse the repository at this point in the history
…m nasm.us.

Downloading from nasm.us frequently fails. Avoid depending on it.

Change the expected location of nasm in build.rs.
  • Loading branch information
briansmith committed Apr 29, 2021
1 parent 0c69150 commit 508f5a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 75 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ jobs:
with:
persist-credentials: false

- run: powershell -ExecutionPolicy Bypass ./mk/install-build-tools.ps1
- run: ./mk/install-build-tools.ps1

- uses: briansmith/actions-rs-toolchain@v1
with:
Expand Down Expand Up @@ -286,9 +286,7 @@ jobs:
run: mk/install-build-tools.sh --target=${{ matrix.target }} ${{ matrix.features }}

- if: ${{ contains(matrix.host_os, 'windows') }}
run: >
(powershell -ExecutionPolicy Bypass ./mk/install-build-tools.ps1) -and
("$pwd\target\tools" >> $env:GITHUB_PATH)
run: ./mk/install-build-tools.ps1

- uses: briansmith/actions-rs-toolchain@v1
with:
Expand Down
6 changes: 3 additions & 3 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ apply when building from crates.io:
primitives (32- and 64- bit Intel, and 32- and 64-bit ARM), Perl must be
installed and in `$PATH`.

* For Windows targets, `target/tools/nasm[.exe]` is used as the assembler;
[mk/install-build-tools.ps1](mk/install-build-tools.ps1) downloads it for
Windows hosts.
* For Windows targets, `target/tools/windows/nasm/nasm[.exe]` is used as the
assembler. The version to use and how to download it is documented in
[.github/workflows/ci.yml](.github/workflows/ci.yml).

Cross Compiling
---------------
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ fn nasm(file: &Path, arch: &str, out_file: &Path) -> Command {
"x86" => ("win32"),
_ => panic!("unsupported arch: {}", arch),
};
let mut c = Command::new("./target/tools/nasm");
let mut c = Command::new("./target/tools/windows/nasm/nasm");
let _ = c
.arg("-o")
.arg(out_file.to_str().expect("Invalid path"))
Expand Down
73 changes: 6 additions & 67 deletions mk/install-build-tools.ps1
Original file line number Diff line number Diff line change
@@ -1,67 +1,6 @@
function Verify-Or-Delete-File {
param (
[Parameter(Mandatory)]
[string]$File,
[Parameter(Mandatory)]
[string]$ExpectedDigest
)
$ActualDigest = ( Get-FileHash -Algorithm SHA256 $File ).Hash
if ( $ActualDigest -eq $ExpectedDigest )
{
return
}
rm $File
echo "Digest verification failed for $Url; actual $ActualDigest, expected $ExpectedDigest"
exit 1
}

function Download-Zip-and-Extract-File {
param (
[Parameter(Mandatory)]
[string]$Uri,
[Parameter(Mandatory)]
[string]$ZipExpectedDigest,
[Parameter(Mandatory)]
[string]$PathWithinZip,
[Parameter(Mandatory)]
[string]$FileExpectedDigest,
[Parameter(Mandatory)]
[string]$OutFile
)
$TmpZip = New-TemporaryFile
Invoke-WebRequest -Uri $Uri -OutFile $TmpZip.FullName
echo $TmpZip
Verify-Or-Delete-File -File $TmpZip.FullName -ExpectedDigest $ZipExpectedDigest

Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::OpenRead($TmpZip)
$zip.Entries |
Where-Object { $_.FullName -eq $PathWithinZip } |
ForEach-Object {
$TmpFile = New-TemporaryFile
# extract the selected items from the ZIP archive
# and copy them to the out folder
$FileName = $_.Name
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$TmpFile", $true)
Verify-Or-Delete-File -File $TmpFile -ExpectedDigest $FileExpectedDigest
Move-Item -Force $TmpFile $OutFile
}
$zip.Dispose()
}

$tools_dir = "target/tools"
mkdir -Force $tools_dir

# This is the file BoringSSL refers to in
# https://boringssl.googlesource.com/boringssl/+/26f8297177ad8033cc39de84afe9c2000430a66d.
$nasm_version = "nasm-2.13.03"
$nasm_zip = "$nasm_version-win64.zip"
$nasm_zip_sha256 = "B3A1F896B53D07854884C2E0D6BE7DEFBA7EBD09B864BBB9E6D69ADA1C3E989F"
$nasm_exe = "nasm.exe"
$nasm_exe_sha256 = "D8A933BF5CC3597C56193135CB78B225AB225E1F611D2FDB51EF6E3F555B21E3"
Download-Zip-and-Extract-File `
-Uri "https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/$nasm_zip" `
-ZipExpectedDigest "$nasm_zip_sha256" `
-PathWithinZip "$nasm_version/$nasm_exe" `
-FileExpectedDigest "$nasm_exe_sha256" `
-OutFile "$tools_dir/$nasm_exe"
# TODO: Lock this down to a specific commit instead of always using the latest.
git clone `
--branch windows `
--depth 1 `
https://github.com/briansmith/ring-toolchain `
target/tools/windows

0 comments on commit 508f5a3

Please sign in to comment.