Skip to content

Commit

Permalink
Build using CBL-Mariner and LLVM 16.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
BruceForstall committed Aug 8, 2023
1 parent 6e21610 commit 6ebbfad
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 88 deletions.
30 changes: 10 additions & 20 deletions build-coredistools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TargetOSArchitecture=$1
CrossRootfsDirectory=$2

# Set this to 1 to build using CBL-Mariner
CrossBuildUsingMariner=0
CrossBuildUsingMariner=1

EnsureCrossRootfsDirectoryExists () {
if [ ! -d "$CrossRootfsDirectory" ]; then
Expand All @@ -18,9 +18,9 @@ LLVMTargetsToBuild="AArch64;ARM;X86"

# Figure out which `strip` to use. Prefer `llvm-strip` if it is available.
# `llvm-strip` is available in CBL-Mariner container; `strip` is available on macOS.
StripTool=$(command -v strip)
StripTool=$(command -v llvm-strip)
if [ -z "$StripTool" ]; then
StripTool=$(command -v llvm-strip)
StripTool=$(command -v strip)
if [ -z "$StripTool" ]; then
echo "Strip tool not found"
exit 1
Expand All @@ -35,26 +35,14 @@ fi

C_COMPILER=$(command -v clang)
if [ -z "$C_COMPILER" ]; then
C_COMPILER=$(command -v clang-10)
if [ -z "$C_COMPILER" ]; then
C_COMPILER=$(command -v clang-9)
if [ -z "$C_COMPILER" ]; then
echo "C compiler not found"
# Keep going in case cmake can find one?
fi
fi
echo "C compiler not found"
# Keep going in case cmake can find one?
fi

CXX_COMPILER=$(command -v clang++)
if [ -z "$CXX_COMPILER" ]; then
CXX_COMPILER=$(command -v clang++-10)
if [ -z "$CXX_COMPILER" ]; then
CXX_COMPILER=$(command -v clang++-9)
if [ -z "$CXX_COMPILER" ]; then
echo "C++ compiler not found"
# Keep going in case cmake can find one?
fi
fi
echo "C++ compiler not found"
# Keep going in case cmake can find one?
fi

echo "Using C compiler: $C_COMPILER"
Expand Down Expand Up @@ -154,9 +142,11 @@ if [ -z "$CrossRootfsDirectory" ]; then
elif [ $CrossBuildUsingMariner -eq 1 ]; then
BUILD_FLAGS="--sysroot=$CrossRootfsDirectory -target $LLVMHostTriple"
# CBL-Mariner doesn't have `ld` so need to tell clang to use `lld` with "-fuse-ld=lld"
# [old info:]
# CBL-Mariner doesn't seem to have libgcc_s.so in a standard place, so as a hack, add
# -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5
# where it does exist.
# -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5" \
cmake \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -165,7 +155,7 @@ elif [ $CrossBuildUsingMariner -eq 1 ]; then
-DCMAKE_CXX_COMPILER=${CXX_COMPILER} \
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \
-DCMAKE_INSTALL_PREFIX=$StagingDirectory \
-DCMAKE_LIBRARY_PATH=$CrossRootfsDirectory/usr/lib/$LLVMHostTriple \
Expand Down
6 changes: 4 additions & 2 deletions build-tblgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TargetOSArchitecture=$1
CrossRootfsDirectory=$2

# Set this to 1 to build using CBL-Mariner
CrossBuildUsingMariner=0
CrossBuildUsingMariner=1

EnsureCrossRootfsDirectoryExists () {
if [ ! -d "$CrossRootfsDirectory" ]; then
Expand Down Expand Up @@ -87,9 +87,11 @@ if [ -z "$CrossRootfsDirectory" ]; then
elif [ $CrossBuildUsingMariner -eq 1 ]; then
BUILD_FLAGS="--sysroot=$CrossRootfsDirectory"
# CBL-Mariner doesn't have `ld` so need to tell clang to use `lld` with "-fuse-ld=lld"
# [old info:]
# CBL-Mariner doesn't seem to have libgcc_s.so in a standard place, so as a hack, add
# -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5
# where it does exist.
# -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5" \
cmake \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Release \
Expand All @@ -99,7 +101,7 @@ elif [ $CrossBuildUsingMariner -eq 1 ]; then
-DCMAKE_CXX_COMPILER=$(command -v clang++) \
-DCMAKE_C_FLAGS="${BUILD_FLAGS}" \
-DCMAKE_CXX_FLAGS="${BUILD_FLAGS}" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld -L/crossrootfs/x64/usr/lib/gcc/x86_64-linux-gnu/5" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_INCLUDE_PATH=$CrossRootfsDirectory/usr/include \
-DCMAKE_LIBRARY_PATH=$CrossRootfsDirectory/usr/lib/$LLVMHostTriple \
-DLLVM_TARGETS_TO_BUILD=$LLVMTargetsToBuild \
Expand Down
134 changes: 68 additions & 66 deletions coredistools.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Changes to build with CBL-Mariner are commented out and marked "CBL-Mariner"
# Changes to build with CBL-Mariner are marked "CBL-Mariner"

pr:
branches:
Expand Down Expand Up @@ -30,27 +30,27 @@ trigger:
- pack-coredistools.cmd

# CBL-Mariner:
#resources:
# containers:
# - container: linux_x64
# image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-amd64-20230414190614-8100bf7
# - container: linux_arm
# image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-arm-20230414190614-8100bf7
# - container: linux_arm64
# image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-arm64-20230414190614-8100bf7

# Use the following for legacy Ubuntu 18.04 based Arm/Arm64 cross build (x64 build is not cross)
resources:
containers:
- container: linux_x64
image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-amd64
- container: linux_arm
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-20220312201346-b9de666
image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-arm
- container: linux_arm64
image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-arm64-20220312201346-b2c2436
image: mcr.microsoft.com/dotnet-buildtools/prereqs:cbl-mariner-2.0-cross-arm64

# # Use the following for legacy Ubuntu 18.04 based Arm/Arm64 cross build (x64 build is not cross)
# resources:
# containers:
# - container: linux_arm
# image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-20220312201346-b9de666
# - container: linux_arm64
# image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-arm64-20220312201346-b2c2436

variables:
LLVMRepositoryUri: https://github.com/llvm/llvm-project.git
LLVMSourceBundle: llvm-project.bundle
LLVMSourceVersion: llvmorg-16.0.1
LLVMSourceVersion: llvmorg-16.0.3

jobs:

Expand Down Expand Up @@ -85,12 +85,13 @@ jobs:
displayName: Build llvm-tblgen linux

# CBL-Mariner:
#container: linux_x64
container: linux_x64

pool:
# CBL-Mariner:
# vmImage: ubuntu-latest
vmImage: ubuntu-20.04
vmImage: ubuntu-latest
# non-CBL-Mariner:
# vmImage: ubuntu-20.04

workspace:
clean: all
Expand All @@ -99,12 +100,12 @@ jobs:
- template: /eng/download-checkout-llvm.yml

# CBL-Mariner:
#- script: ./build-tblgen.sh linux-x64 /crossrootfs/x64
# displayName: Build llvm-tblgen
- script: ./build-tblgen.sh linux-x64 /crossrootfs/x64
displayName: Build llvm-tblgen

# non-CBL-Mariner:
- script: ./build-tblgen.sh linux-x64
displayName: Build llvm-tblgen
#- script: ./build-tblgen.sh linux-x64
# displayName: Build llvm-tblgen

- publish: $(Build.SourcesDirectory)/bin/llvm-tblgen
artifact: tblgen-linux
Expand All @@ -117,8 +118,9 @@ jobs:
- checkout_llvm
- build_tblgen_linux
# CBL-Mariner:
# displayName: Build coredistools Linux x64/arm/arm64
displayName: Build coredistools Linux arm/arm64
displayName: Build coredistools Linux x64/arm/arm64
# non-CBL-Mariner:
# displayName: Build coredistools Linux arm/arm64

container: $[ variables['ContainerImage'] ]

Expand All @@ -127,11 +129,11 @@ jobs:

strategy:
matrix:
# CBL-Mariner:
#x64:
# ContainerImage: linux_x64
# CrossRootfsDirectory: /crossrootfs/x64
# TargetOSArchitecture: linux-x64
# CBL-Mariner: (x64 section)
x64:
ContainerImage: linux_x64
CrossRootfsDirectory: /crossrootfs/x64
TargetOSArchitecture: linux-x64

arm:
ContainerImage: linux_arm
Expand Down Expand Up @@ -171,43 +173,43 @@ jobs:

################################ Cross-build coredistools for linux-x64: only non-CBL-Mariner

- job: build_coredistools_linux
dependsOn:
- checkout_llvm
- build_tblgen_linux
displayName: Build coredistools Linux x64

pool:
vmImage: ubuntu-20.04

variables:
TargetOSArchitecture: linux-x64

workspace:
clean: all

steps:
- template: /eng/download-checkout-llvm.yml

- download: current
artifact: tblgen-linux
displayName: Download llvm-tblgen

- script: |
chmod +x $(Pipeline.Workspace)/tblgen-linux/llvm-tblgen
displayName: Make llvm-tblgen executable
- script: |
echo "##vso[task.prependpath]$(Pipeline.Workspace)/tblgen-linux"
displayName: Add llvm-tblgen to the PATH
- script: |
./build-coredistools.sh $(TargetOSArchitecture)
displayName: Build coredistools
- publish: $(Build.SourcesDirectory)/artifacts/$(TargetOSArchitecture)/bin/libcoredistools.so
artifact: coredistools-$(TargetOSArchitecture)
displayName: Publish coredistools
# - job: build_coredistools_linux
# dependsOn:
# - checkout_llvm
# - build_tblgen_linux
# displayName: Build coredistools Linux x64
#
# pool:
# vmImage: ubuntu-20.04
#
# variables:
# TargetOSArchitecture: linux-x64
#
# workspace:
# clean: all
#
# steps:
# - template: /eng/download-checkout-llvm.yml
#
# - download: current
# artifact: tblgen-linux
# displayName: Download llvm-tblgen
#
# - script: |
# chmod +x $(Pipeline.Workspace)/tblgen-linux/llvm-tblgen
# displayName: Make llvm-tblgen executable
#
# - script: |
# echo "##vso[task.prependpath]$(Pipeline.Workspace)/tblgen-linux"
# displayName: Add llvm-tblgen to the PATH
#
# - script: |
# ./build-coredistools.sh $(TargetOSArchitecture)
# displayName: Build coredistools
#
# - publish: $(Build.SourcesDirectory)/artifacts/$(TargetOSArchitecture)/bin/libcoredistools.so
# artifact: coredistools-$(TargetOSArchitecture)
# displayName: Publish coredistools

################################ Build llvm-tblgen on Mac (x64)

Expand Down Expand Up @@ -345,7 +347,7 @@ jobs:
dependsOn:
- crossbuild_coredistools_linux
# only non-CBL-Mariner:
- build_coredistools_linux
# - build_coredistools_linux
- build_coredistools_macos
- build_coredistools_windows
displayName: Build coredistools NuGet packages
Expand Down

0 comments on commit 6ebbfad

Please sign in to comment.