Skip to content

Commit 9d342d5

Browse files
authored
Build as.exe on windows (#10)
Build our `GNU as` wrapper around LLVM's `llvm-mc` assembler entirely on Windows, using MSVC. This is required to satisfy the API Scan requirements for the binary. As part of this, the wrapper transitioned from using the GNU `getopt` command-line parsing API to a header-only portable C++ library, `cxxopt`. The move was necessary because the MSVC toolchain lacks an implementation of `getopt` (while it is part of the MinGW's POSIX compatibility layer, and previously the utility was built with MinGW on Linux). Additionally, the Linux hosts now use g++ 13 to build the utilities. Pipeline error handling has been fixed, where it would previously ignore build errors leading to false positive "green" builds.
1 parent dae2eb6 commit 9d342d5

18 files changed

+331
-251
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
url = https://github.com/llvm/llvm-project.git
44
shallow = true
55
branch = release/13.x
6+
[submodule "cxxopts"]
7+
path = external/cxxopts
8+
url = https://github.com/jarro2783/cxxopts.git
9+
branch = master

build-common.cmd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set MY_DIR=%~dp0
2+
set HOST=windows
3+
set BUILD_DIR=%MY_DIR%\xa-build
4+
set ARTIFACTS_DIR=%MY_DIR%\artifacts
5+
set HOST_ARTIFACTS_DIR=%ARTIFACTS_DIR%\%HOST%
6+
set HOST_ARTIFACTS_BIN_DIR=%HOST_ARTIFACTS_DIR%\bin
7+
set CMAKE_VS_GENERATOR=Visual Studio 17 2022
8+
set MSVC_RUNTIME_LIBRARY="MultiThreaded"
9+
10+
mkdir %HOST_ARTIFACTS_BIN_DIR%

build-llvm-azure.cmd

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
FOR /F "tokens=1 delims=" %%F IN ('.\scripts\vswhere.cmd') DO SET result=%%F
2-
CALL "%result%\Common7\Tools\VsDevCmd.bat"
3-
IF ERRORLEVEL 1 CALL:FAILED_CASE
4-
5-
echo "VS path: %result%"
6-
7-
CALL ".\build-llvm.cmd"
8-
IF ERRORLEVEL 1 CALL:FAILED_CASE
9-
GOTO END_CASE
10-
11-
:FAILED_CASE
12-
echo "Failed to find an instance of Visual Studio. Please check it is correctly installed."
13-
GOTO END_CASE
14-
:END_CASE
15-
GOTO :EOF
1+
FOR /F "tokens=1 delims=" %%F IN ('.\scripts\vswhere.cmd') DO SET result=%%F
2+
CALL "%result%\Common7\Tools\VsDevCmd.bat"
3+
IF %ERRORLEVEL% GEQ 1 CALL:FAILED_CASE
4+
5+
echo "VS path: %result%"
6+
7+
CALL ".\build-llvm.cmd"
8+
IF %ERRORLEVEL% GEQ 1 CALL:FAILED_CASE
9+
GOTO END_CASE
10+
11+
:FAILED_CASE
12+
echo "Failed to find an instance of Visual Studio. Please check it is correctly installed."
13+
exit /B %errorlevel%
14+
GOTO END_CASE
15+
:END_CASE
16+
GOTO :EOF

build-llvm.cmd

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
1-
set MY_DIR=%~dp0
2-
set HOST=windows
3-
set BUILD_DIR=%MY_DIR%\xa-build
4-
set ARTIFACTS_DIR=%MY_DIR%\artifacts
1+
call build-common.cmd
2+
53
set SOURCE_DIR=%MY_DIR%external\llvm\llvm
64

75
set PROJECTS=lld
86
set TARGETS=X86;ARM;AArch64
97
set BINARIES=llvm-mc.exe llvm-strip.exe lld.exe llc.exe
108
set PDBS=llvm-mc.pdb llvm-strip.pdb lld.pdb llc.pdb
119

12-
set HOST_BUILD_DIR=%BUILD_DIR%\%HOST%
10+
set HOST_BUILD_DIR=%BUILD_DIR%\%HOST%\llvm
1311
set HOST_BIN_DIR=%HOST_BUILD_DIR%\Release\bin
14-
set HOST_ARTIFACTS_DIR=%ARTIFACTS_DIR%\%HOST%
12+
1513
set LLVM_VERSION_FILE=%HOST_ARTIFACTS_DIR%\llvm-version.txt
1614
set CXXFLAGS="/Qspectre /sdl /guard:cf"
1715

1816
if exist %HOST_BUILD_DIR% (rmdir /S /Q %HOST_BUILD_DIR%)
1917
mkdir %HOST_BUILD_DIR%
2018

21-
if exist %HOST_ARTIFACTS_DIR% (rmdir /S /Q %HOST_ARTIFACTS_DIR%)
22-
mkdir %HOST_ARTIFACTS_DIR%\bin
23-
2419
cd %HOST_BUILD_DIR%
2520

2621
cmake --version
2722
cmake --help
2823

29-
cmake -G "Visual Studio 17 2022" -A x64 ^
24+
cmake -G "%CMAKE_VS_GENERATOR%" -A x64 ^
3025
-DCMAKE_EXE_LINKER_FLAGS_INIT="/PROFILE /DYNAMICBASE /CETCOMPAT /guard:cf" ^
3126
-DBUILD_SHARED_LIBS=OFF ^
3227
-DCMAKE_BUILD_TYPE=Release ^
33-
-DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" ^
28+
-DCMAKE_MSVC_RUNTIME_LIBRARY="%MSVC_RUNTIME_LIBRARY%" ^
3429
-DLLVM_BUILD_BENCHMARKS=OFF ^
3530
-DLLVM_BUILD_DOCS=OFF ^
3631
-DLLVM_BUILD_EXAMPLES=OFF ^
@@ -59,19 +54,33 @@ cmake -G "Visual Studio 17 2022" -A x64 ^
5954
-DLLVM_USE_CRT_MINSIZEREL=MT ^
6055
-DLLVM_USE_CRT_RELEASE=MT ^
6156
%SOURCE_DIR%
57+
IF %ERRORLEVEL% GEQ 1 EXIT /B 1
6258

6359
msbuild /p:Configuration=Release /m tools\llvm-mc\llvm-mc.vcxproj
60+
IF %ERRORLEVEL% GEQ 1 EXIT /B 2
61+
6462
msbuild /p:Configuration=Release /m tools\llvm-objcopy\llvm-objcopy.vcxproj
63+
IF %ERRORLEVEL% GEQ 1 EXIT /B 3
64+
6565
msbuild /p:Configuration=Release /m tools\lld\tools\lld\lld.vcxproj
66+
IF %ERRORLEVEL% GEQ 1 EXIT /B 4
67+
6668
msbuild /p:Configuration=Release /m tools\llc\llc.vcxproj
69+
IF %ERRORLEVEL% GEQ 1 EXIT /B 5
6770

6871
move %HOST_BIN_DIR%\llvm-objcopy.exe %HOST_BIN_DIR%\llvm-strip.exe
72+
IF %ERRORLEVEL% GEQ 1 EXIT /B 6
73+
6974
move %HOST_BIN_DIR%\llvm-objcopy.pdb %HOST_BIN_DIR%\llvm-strip.pdb
75+
IF %ERRORLEVEL% GEQ 1 EXIT /B 7
76+
7077
for %%b in (%BINARIES%) DO (
71-
copy %HOST_BIN_DIR%\%%b %HOST_ARTIFACTS_DIR%\bin\%%b
78+
copy %HOST_BIN_DIR%\%%b %HOST_ARTIFACTS_BIN_DIR%\%%b
79+
IF %ERRORLEVEL% GEQ 1 EXIT /B 8
7280
)
7381
for %%p in (%PDBS%) DO (
74-
copy %HOST_BIN_DIR%\%%p %HOST_ARTIFACTS_DIR%\bin\%%p
82+
copy %HOST_BIN_DIR%\%%p %HOST_ARTIFACTS_BIN_DIR%\%%p
83+
IF %ERRORLEVEL% GEQ 1 EXIT /B 9
7584
)
7685

7786
cd %MY_DIR%

build-llvm.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
3+
set -e
24

35
MY_NAME="$(basename $0)"
46
MY_DIR="$(cd $(dirname $0);pwd)"
@@ -109,6 +111,32 @@ function build()
109111
fi
110112
}
111113

114+
function print_compiler_info()
115+
{
116+
local path="$(which ${1})"
117+
118+
if [ -z "${path}" ]; then
119+
echo "Compiler ${1} not found"
120+
return
121+
fi
122+
123+
echo "Compiler ${1} found:"
124+
"${path}" --version
125+
echo
126+
}
127+
128+
if [ "${HOST}" == "linux" ]; then
129+
echo "Compilers found:"
130+
131+
print_compiler_info gcc
132+
print_compiler_info g++
133+
134+
for v in 10 11 12 13 14; do
135+
print_compiler_info gcc-${v}
136+
print_compiler_info g++-${v}
137+
done
138+
fi
139+
112140
create_empty_dir "${MY_BUILD_DIR}"
113141
create_dir "${HOST_ARTIFACTS_BIN_DIR}"
114142
create_dir "${HOST_ARTIFACTS_LIB_DIR}"

build-tools/automation/azure-pipelines.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ extends:
115115

116116
- script: ./build-llvm.sh
117117
env:
118-
CC: gcc-10
119-
CXX: g++-10
118+
CC: gcc-13
119+
CXX: g++-13
120120
displayName: Build LLVM
121121

122122
- script: ./build-xa-utils.sh
123123
env:
124-
CC: gcc-10
125-
CXX: g++-10
124+
CC: gcc-13
125+
CXX: g++-13
126126
displayName: Build utilities
127127

128128
- script: |
@@ -140,6 +140,7 @@ extends:
140140
vmImage: macOS-latest
141141
${{ else }}:
142142
name: VSEng-Xamarin-RedmondMac-Android-Untrusted
143+
demands: macOS.Name -equals Monterey
143144
os: macOS
144145
templateContext:
145146
outputs:
@@ -197,10 +198,12 @@ extends:
197198
- checkout: self
198199
submodules: recursive
199200

201+
- script: ./build-xa-utils-azure.cmd
202+
displayName: Build utilities
203+
200204
- script: ./build-llvm-azure.cmd
201205
displayName: Build Windows LLVM
202206

203-
204207
- stage: package
205208
displayName: Package Stage
206209
dependsOn: build

build-xa-utils-azure.cmd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FOR /F "tokens=1 delims=" %%F IN ('.\scripts\vswhere.cmd') DO SET result=%%F
2+
CALL "%result%\Common7\Tools\VsDevCmd.bat"
3+
IF %ERRORLEVEL% GEQ 1 CALL:FAILED_CASE
4+
5+
echo "VS path: %result%"
6+
7+
CALL ".\build-xa-utils.cmd"
8+
IF %ERRORLEVEL% GEQ 1 CALL:FAILED_CASE
9+
GOTO END_CASE
10+
11+
:FAILED_CASE
12+
echo "Failed to find an instance of Visual Studio. Please check it is correctly installed."
13+
exit /B %errorlevel%
14+
GOTO END_CASE
15+
:END_CASE
16+
GOTO :EOF

build-xa-utils.cmd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
call build-common.cmd
2+
3+
set SOURCE_DIR=%MY_DIR%src
4+
set HOST_BUILD_DIR=%BUILD_DIR%\%HOST%\xa-utils
5+
set HOST_BIN_DIR=%HOST_BUILD_DIR%\bin\Release
6+
7+
if exist %HOST_BUILD_DIR% (rmdir /S /Q %HOST_BUILD_DIR%)
8+
mkdir %HOST_BUILD_DIR%
9+
10+
cd %HOST_BUILD_DIR%
11+
12+
cmake --version
13+
14+
cmake -G "%CMAKE_VS_GENERATOR%" -A x64 ^
15+
-DCMAKE_BUILD_TYPE=Release ^
16+
-DCMAKE_MSVC_RUNTIME_LIBRARY="%MSVC_RUNTIME_LIBRARY%" ^
17+
-DBINUTILS_VERSION="2.38" ^
18+
%SOURCE_DIR%
19+
IF %ERRORLEVEL% GEQ 1 EXIT /B 1
20+
21+
msbuild /p:Configuration=Release /m xa-utilities.sln
22+
IF %ERRORLEVEL% GEQ 1 EXIT /B 2
23+
24+
copy %HOST_BIN_DIR%\as.exe %HOST_ARTIFACTS_BIN_DIR%\as.exe
25+
IF %ERRORLEVEL% GEQ 1 EXIT /B 3
26+
27+
copy %HOST_BIN_DIR%\as.pdb %HOST_ARTIFACTS_BIN_DIR%\as.pdb
28+
IF %ERRORLEVEL% GEQ 1 EXIT /B 4
29+
30+
cd %MY_DIR%

build-xa-utils.sh

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#!/bin/bash -e
1+
#!/bin/bash
2+
3+
set -e
24

35
MY_NAME="$(basename $0)"
46
MY_DIR="$(cd $(dirname $0);pwd)"
@@ -86,18 +88,3 @@ esac
8688

8789
(cd "${MY_BUILD_DIR}"; configure_${HOST})
8890
(cd "${MY_BUILD_DIR}"; build "${HOST}")
89-
90-
if [ "${HOST}" != "linux" ]; then
91-
exit 0
92-
fi
93-
94-
MY_BUILD_DIR="${MY_BUILD_DIR}-windows"
95-
HOST_ARTIFACTS_DIR="${ARTIFACTS_DIR}/windows"
96-
HOST_ARTIFACTS_BIN_DIR="${HOST_ARTIFACTS_DIR}/bin"
97-
HOST_BIN_DIR="${MY_BUILD_DIR}/bin"
98-
99-
create_empty_dir "${MY_BUILD_DIR}"
100-
create_dir "${HOST_ARTIFACTS_BIN_DIR}"
101-
102-
(cd "${MY_BUILD_DIR}"; configure_windows)
103-
(cd "${MY_BUILD_DIR}"; build windows)

external/cxxopts

Submodule cxxopts added at 3bf2684

0 commit comments

Comments
 (0)