Skip to content

Commit 15c823a

Browse files
committed
Build: Replace use of Yasm with use of Nasm for Windows assembly.
Match BoringSSL. According to the Chromium discussion about nasm, it is also substantially faster.
1 parent 08c5854 commit 15c823a

File tree

4 files changed

+72
-37
lines changed

4 files changed

+72
-37
lines changed

.github/workflows/ci.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ jobs:
6363
steps:
6464
- uses: actions/checkout@v2
6565

66-
- run: >
67-
(powershell -ExecutionPolicy Bypass ./mk/install-build-tools.ps1) -and
68-
("$pwd\target\tools" >> $env:GITHUB_PATH)
66+
- run: powershell -ExecutionPolicy Bypass ./mk/install-build-tools.ps1
6967

7068
- uses: actions-rs/toolchain@v1
7169
with:

BUILDING.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ Builds directly from Git
2626
------------------------
2727

2828
If you want to hack on *ring* then you need to build it directly from its Git
29-
repository. In this case, you must also have Perl installed, because the
30-
assembly language modules inherited from BoringSSL (inherited from OpenSSL)
31-
use Perl as a macro assembly language.
29+
repository. There are some additional requirements for doing this that do not
30+
apply when building from crates.io:
3231

33-
When building from Git for Windows, directories containing yasm.exe and
34-
perl.exe must be in `%PATH%`, where yasm.exe is
35-
[Yasm](http://yasm.tortall.net/Download.html) 1.3 or later and where perl.exe
36-
is recommended to be [Strawberry Perl](http://strawberryperl.com).
32+
* For any target for which *ring* has assembly language implementations of
33+
primitives (32- and 64- bit Intel, and 32- and 64-bit ARM), Perl must be
34+
installed and in `$PATH`.
3735

36+
* For Windows targets, `target/tools/nasm[.exe]` is used as the assembler;
37+
[mk/install-build-tools.ps1](mk/install-build-tools.ps1) downloads it for
38+
Windows hosts.
3839

3940
Cross Compiling
4041
---------------

build.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn pregenerate_asm_main() {
322322
let srcs = asm_srcs(perlasm_src_dsts);
323323
for src in srcs {
324324
let obj_path = obj_path(&pregenerated, &src, MSVC_OBJ_EXT);
325-
run_command(yasm(&src, target_arch, &obj_path));
325+
run_command(nasm(&src, target_arch, &obj_path));
326326
}
327327
}
328328
}
@@ -523,7 +523,7 @@ fn compile(
523523
let cmd = if target.os != WINDOWS || ext != "asm" {
524524
cc(p, ext, target, warnings_are_errors, &out_path)
525525
} else {
526-
yasm(p, &target.arch, &out_path)
526+
nasm(p, &target.arch, &out_path)
527527
};
528528

529529
run_command(cmd);
@@ -637,21 +637,20 @@ fn cc(
637637
c
638638
}
639639

640-
fn yasm(file: &Path, arch: &str, out_file: &Path) -> Command {
641-
let (oformat, machine) = match arch {
642-
"x86_64" => ("--oformat=win64", "--machine=amd64"),
643-
"x86" => ("--oformat=win32", "--machine=x86"),
640+
fn nasm(file: &Path, arch: &str, out_file: &Path) -> Command {
641+
let oformat = match arch {
642+
"x86_64" => ("win64"),
643+
"x86" => ("win32"),
644644
_ => panic!("unsupported arch: {}", arch),
645645
};
646-
let mut c = Command::new("yasm.exe");
646+
let mut c = Command::new("./target/tools/nasm");
647647
let _ = c
648-
.arg("-X")
649-
.arg("vc")
650-
.arg("--dformat=cv8")
651-
.arg(oformat)
652-
.arg(machine)
653648
.arg("-o")
654649
.arg(out_file.to_str().expect("Invalid path"))
650+
.arg("-f")
651+
.arg(oformat)
652+
.arg("-Xgnu")
653+
.arg("-gcv8")
655654
.arg(file);
656655
c
657656
}

mk/install-build-tools.ps1

+52-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
1-
function Download-File {
1+
function Verify-Or-Delete-File {
22
param (
33
[Parameter(Mandatory)]
4-
[string]$Url,
4+
[string]$File,
55
[Parameter(Mandatory)]
6-
[string]$ExpectedDigest,
7-
[Parameter(Mandatory)]
8-
[string]$OutFile
6+
[string]$ExpectedDigest
97
)
10-
$TmpFile = New-TemporaryFile
11-
Invoke-WebRequest -Uri $Url -OutFile $TmpFile.FullName
12-
$ActualDigest = ( Get-FileHash -Algorithm SHA256 $TmpFile ).Hash
8+
$ActualDigest = ( Get-FileHash -Algorithm SHA256 $File ).Hash
139
if ( $ActualDigest -eq $ExpectedDigest )
1410
{
15-
Move-Item -Force $TmpFile $OutFile
1611
return
1712
}
18-
13+
rm $File
1914
echo "Digest verification failed for $Url; actual $ActualDigest, expected $ExpectedDigest"
20-
rm $TmpFile
2115
exit 1
2216
}
2317

18+
function Download-Zip-and-Extract-File {
19+
param (
20+
[Parameter(Mandatory)]
21+
[string]$Uri,
22+
[Parameter(Mandatory)]
23+
[string]$ZipExpectedDigest,
24+
[Parameter(Mandatory)]
25+
[string]$PathWithinZip,
26+
[Parameter(Mandatory)]
27+
[string]$FileExpectedDigest,
28+
[Parameter(Mandatory)]
29+
[string]$OutFile
30+
)
31+
$TmpZip = New-TemporaryFile
32+
Invoke-WebRequest -Uri $Uri -OutFile $TmpZip.FullName
33+
echo $TmpZip
34+
Verify-Or-Delete-File -File $TmpZip.FullName -ExpectedDigest $ZipExpectedDigest
35+
36+
Add-Type -AssemblyName System.IO.Compression.FileSystem
37+
$zip = [System.IO.Compression.ZipFile]::OpenRead($TmpZip)
38+
$zip.Entries |
39+
Where-Object { $_.FullName -eq $PathWithinZip } |
40+
ForEach-Object {
41+
$TmpFile = New-TemporaryFile
42+
# extract the selected items from the ZIP archive
43+
# and copy them to the out folder
44+
$FileName = $_.Name
45+
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, "$TmpFile", $true)
46+
Verify-Or-Delete-File -File $TmpFile -ExpectedDigest $FileExpectedDigest
47+
Move-Item -Force $TmpFile $OutFile
48+
}
49+
$zip.Dispose()
50+
}
51+
2452
$tools_dir = "target/tools"
2553
mkdir -Force $tools_dir
2654

27-
Download-File `
28-
-Url 'https://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe' `
29-
-ExpectedDigest D160B1D97266F3F28A71B4420A0AD2CD088A7977C2DD3B25AF155652D8D8D91F `
30-
-OutFile $tools_dir/yasm.exe
55+
# This is the file BoringSSL refers to in
56+
# https://boringssl.googlesource.com/boringssl/+/26f8297177ad8033cc39de84afe9c2000430a66d.
57+
$nasm_version = "nasm-2.13.03"
58+
$nasm_zip = "$nasm_version-win64.zip"
59+
$nasm_zip_sha256 = "B3A1F896B53D07854884C2E0D6BE7DEFBA7EBD09B864BBB9E6D69ADA1C3E989F"
60+
$nasm_exe = "nasm.exe"
61+
$nasm_exe_sha256 = "D8A933BF5CC3597C56193135CB78B225AB225E1F611D2FDB51EF6E3F555B21E3"
62+
Download-Zip-and-Extract-File `
63+
-Uri "https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/win64/$nasm_zip" `
64+
-ZipExpectedDigest "$nasm_zip_sha256" `
65+
-PathWithinZip "$nasm_version/$nasm_exe" `
66+
-FileExpectedDigest "$nasm_exe_sha256" `
67+
-OutFile "$tools_dir/$nasm_exe"

0 commit comments

Comments
 (0)