about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-10-04 18:53:52 +0200
committerPietro Albini <pietro@pietroalbini.org>2019-10-25 16:03:07 +0200
commitc5bbde3e2f0f681fb8ecded09924246cf5c508da (patch)
tree07a826a5fa8eab6c6b723876be0d69293d8721bd /src
parenta36077235e800cd2d46aa70151de8c7eac0ced5b (diff)
downloadrust-c5bbde3e2f0f681fb8ecded09924246cf5c508da.tar.gz
rust-c5bbde3e2f0f681fb8ecded09924246cf5c508da.zip
ci: extract installing clang into a script
Diffstat (limited to 'src')
-rw-r--r--src/ci/azure-pipelines/steps/install-clang.yml46
-rw-r--r--src/ci/azure-pipelines/steps/run.yml6
-rwxr-xr-xsrc/ci/scripts/install-clang.sh42
-rw-r--r--src/ci/shared.sh11
4 files changed, 58 insertions, 47 deletions
diff --git a/src/ci/azure-pipelines/steps/install-clang.yml b/src/ci/azure-pipelines/steps/install-clang.yml
deleted file mode 100644
index 14daf81b430..00000000000
--- a/src/ci/azure-pipelines/steps/install-clang.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-steps:
-
-- bash: |
-    set -e
-    curl -f http://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-apple-darwin.tar.xz | tar xJf -
-
-    export CC=`pwd`/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang
-    echo "##vso[task.setvariable variable=CC]$CC"
-
-    export CXX=`pwd`/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang++
-    echo "##vso[task.setvariable variable=CXX]$CXX"
-
-    # Configure `AR` specifically so rustbuild doesn't try to infer it as
-    # `clang-ar` by accident.
-    echo "##vso[task.setvariable variable=AR]ar"
-  displayName: Install clang (OSX)
-  condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))
-
-# If we're compiling for MSVC then we, like most other distribution builders,
-# switch to clang as the compiler. This'll allow us eventually to enable LTO
-# amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
-# clang has an output mode compatible with MinGW that we need. If it does we
-# should switch to clang for MinGW as well!
-#
-# Note that the LLVM installer is an NSIS installer
-#
-# Original downloaded here came from
-# http://releases.llvm.org/7.0.0/LLVM-7.0.0-win64.exe
-# That installer was run through `wine` on Linux and then the resulting
-# installation directory (found in `$HOME/.wine/drive_c/Program Files/LLVM`) was
-# packaged up into a tarball. We've had issues otherwise that the installer will
-# randomly hang, provide not a lot of useful information, pollute global state,
-# etc. In general the tarball is just more confined and easier to deal with when
-# working with various CI environments.
-- bash: |
-    set -e
-    mkdir -p citools
-    cd citools
-    curl -f https://rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com/rustc/LLVM-7.0.0-win64.tar.gz | tar xzf -
-    echo "##vso[task.setvariable variable=RUST_CONFIGURE_ARGS]$RUST_CONFIGURE_ARGS --set llvm.clang-cl=`pwd`/clang-rust/bin/clang-cl.exe"
-  condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'), eq(variables['MINGW_URL'],''))
-  displayName: Install clang (Windows)
-
-# Note that we don't install clang on Linux since its compiler story is just so
-# different. Each container has its own toolchain configured appropriately
-# already.
diff --git a/src/ci/azure-pipelines/steps/run.yml b/src/ci/azure-pipelines/steps/run.yml
index 66405f2d2bf..abf6164b8b7 100644
--- a/src/ci/azure-pipelines/steps/run.yml
+++ b/src/ci/azure-pipelines/steps/run.yml
@@ -57,7 +57,11 @@ steps:
   displayName: Install sccache
   condition: and(succeeded(), not(variables.SKIP_JOB))
 
-- template: install-clang.yml
+- bash: src/ci/scripts/install-clang.sh
+  env:
+    AGENT_OS: $(Agent.OS)
+  displayName: Install clang
+  condition: and(succeeded(), not(variables.SKIP_JOB))
 
 # Switch to XCode 9.3 on OSX since it seems to be the last version that supports
 # i686-apple-darwin. We'll eventually want to upgrade this and it will probably
diff --git a/src/ci/scripts/install-clang.sh b/src/ci/scripts/install-clang.sh
new file mode 100755
index 00000000000..79cbc73a61a
--- /dev/null
+++ b/src/ci/scripts/install-clang.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# This script installs clang on the local machine. Note that we don't install
+# clang on Linux since its compiler story is just so different. Each container
+# has its own toolchain configured appropriately already.
+
+set -euo pipefail
+IFS=$'\n\t'
+
+source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
+
+if isMacOS; then
+    curl -f https://rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com/rustc/clang%2Bllvm-7.0.0-x86_64-apple-darwin.tar.xz | tar xJf -
+
+    ciCommandSetEnv CC "$(pwd)/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang"
+    ciCommandSetEnv CXX "$(pwd)/clang+llvm-7.0.0-x86_64-apple-darwin/bin/clang++"
+
+    # Configure `AR` specifically so rustbuild doesn't try to infer it as
+    # `clang-ar` by accident.
+    ciCommandSetEnv AR "ar"
+elif isWindows; then
+    # If we're compiling for MSVC then we, like most other distribution builders,
+    # switch to clang as the compiler. This'll allow us eventually to enable LTO
+    # amongst LLVM and rustc. Note that we only do this on MSVC as I don't think
+    # clang has an output mode compatible with MinGW that we need. If it does we
+    # should switch to clang for MinGW as well!
+    #
+    # Note that the LLVM installer is an NSIS installer
+    #
+    # Original downloaded here came from
+    # http://releases.llvm.org/7.0.0/LLVM-7.0.0-win64.exe
+    # That installer was run through `wine` on Linux and then the resulting
+    # installation directory (found in `$HOME/.wine/drive_c/Program Files/LLVM`) was
+    # packaged up into a tarball. We've had issues otherwise that the installer will
+    # randomly hang, provide not a lot of useful information, pollute global state,
+    # etc. In general the tarball is just more confined and easier to deal with when
+    # working with various CI environments.
+
+    mkdir -p citools
+    cd citools
+    curl -f "${MIRRORS_BASE}/LLVM-7.0.0-win64.tar.gz" | tar xzf -
+    ciCommandSetEnv RUST_CONFIGURE_ARGS "${RUST_CONFIGURE_ARGS} --set llvm.clang-cl=$(pwd)/clang-rust/bin/clang-cl.exe"
+fi
diff --git a/src/ci/shared.sh b/src/ci/shared.sh
index 49fe3841ceb..3d54c94de38 100644
--- a/src/ci/shared.sh
+++ b/src/ci/shared.sh
@@ -55,3 +55,14 @@ function ciCommandAddPath {
 
     echo "##vso[task.prependpath]${path}"
 }
+
+function ciCommandSetEnv {
+    if [[ $# -ne 2 ]]; then
+        echo "usage: $0 <name> <value>"
+        exit 1
+    fi
+    name="$1"
+    value="$2"
+
+    echo "##vso[task.setvariable variable=${name}]${value}"
+}