From 1623328e5d3384597e7922f00690fe5c8a86a2c4 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 14:30:25 +0300 Subject: [PATCH 01/17] dev --- Dockerfile | 13 +++++++++++++ docker-compose.yml | 8 ++++++++ install.sh | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 install.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000000..3969055bc3e4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM debian:stable + +RUN mkdir -p /app \ + && apt-get -y update \ + && apt-get install -y curl wget cmake build-essential llvm lld clang \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app +COPY . /app + +RUN /bin/bash install.sh + +CMD /bin/bash diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000000..3b839d985f97 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + + app: + build: + context: . + volumes: + - ./:/app diff --git a/install.sh b/install.sh new file mode 100755 index 000000000000..ff4371bc3123 --- /dev/null +++ b/install.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +if test "$BASH" = "" || "$BASH" -uc "a=();true \"\${a[@]}\"" 2>/dev/null; then + # Bash 4.4, Zsh + set -euo pipefail +else + # Bash 4.3 and older chokes on empty arrays with set -u. + set -eo pipefail +fi +shopt -s nullglob globstar +export DEBIAN_FRONTEND=noninteractive + + +mkdir -p build +cd /app/build +cmake .. +make install From 41517b8b22ece0ca0b8dd97079a0257f3f342cbf Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 14:38:53 +0300 Subject: [PATCH 02/17] dev --- Dockerfile | 7 ++++++- install.sh | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3969055bc3e4..14810f76e7b7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,12 @@ FROM debian:stable RUN mkdir -p /app \ && apt-get -y update \ - && apt-get install -y curl wget cmake build-essential llvm lld clang \ + && apt-get install -y curl wget cmake build-essential \ + # install llvm, clang, ldd + && wget https://apt.llvm.org/llvm.sh \ + && chmod +x llvm.sh \ + && ./llvm.sh 11 \ + && rm -rf ./llvm.sh \ && rm -rf /var/lib/apt/lists/* WORKDIR /app diff --git a/install.sh b/install.sh index ff4371bc3123..dfa69304ee29 100755 --- a/install.sh +++ b/install.sh @@ -14,3 +14,4 @@ mkdir -p build cd /app/build cmake .. make install +cd /app/ From 60e4d57e5376dcd8256cb14eef30a0e6147fb967 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 14:47:32 +0300 Subject: [PATCH 03/17] dev --- Dockerfile | 2 +- llvm.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 llvm.sh diff --git a/Dockerfile b/Dockerfile index 14810f76e7b7..8b90cef37845 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM debian:stable RUN mkdir -p /app \ && apt-get -y update \ - && apt-get install -y curl wget cmake build-essential \ + && apt-get install -y curl wget cmake build-essential lsb-release software-properties-common \ # install llvm, clang, ldd && wget https://apt.llvm.org/llvm.sh \ && chmod +x llvm.sh \ diff --git a/llvm.sh b/llvm.sh new file mode 100755 index 000000000000..58eef27644b5 --- /dev/null +++ b/llvm.sh @@ -0,0 +1,77 @@ +#!/bin/bash +################################################################################ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +################################################################################ +# +# This script will install the llvm toolchain on the different +# Debian and Ubuntu versions + +set -eux + +# Check for required tools +needed_binaries=(lsb_release wget add-apt-repository) +missing_binaries=() +for binary in "${needed_binaries[@]}"; do + if ! which $binary &>/dev/null ; then + missing_binaries+=($binary) + fi +done +if [[ ${#missing_binaries[@]} -gt 0 ]] ; then + echo "You are missing some tools this script requires: ${missing_binaries[@]}" + echo "(hint: apt install lsb-release wget software-properties-common)" + exit 4 +fi + +# read optional command line argument +LLVM_VERSION=11 +if [ "$#" -eq 1 ]; then + LLVM_VERSION=$1 +fi + +DISTRO=$(lsb_release -is) +VERSION=$(lsb_release -sr) +DIST_VERSION="${DISTRO}_${VERSION}" + +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root!" + exit 1 +fi + +declare -A LLVM_VERSION_PATTERNS +LLVM_VERSION_PATTERNS[9]="-9" +LLVM_VERSION_PATTERNS[10]="-10" +LLVM_VERSION_PATTERNS[11]="-11" +LLVM_VERSION_PATTERNS[12]="" + +if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then + echo "This script does not support LLVM version $LLVM_VERSION" + exit 3 +fi + +LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} + +# find the right repository name for the distro and version +case "$DIST_VERSION" in + Debian_9* ) REPO_NAME="deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch$LLVM_VERSION_STRING main" ;; + Debian_10* ) REPO_NAME="deb http://apt.llvm.org/buster/ llvm-toolchain-buster$LLVM_VERSION_STRING main" ;; + Debian_unstable ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; + Debian_testing ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; + Ubuntu_16.04 ) REPO_NAME="deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial$LLVM_VERSION_STRING main" ;; + Ubuntu_18.04 ) REPO_NAME="deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic$LLVM_VERSION_STRING main" ;; + Ubuntu_18.10 ) REPO_NAME="deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic$LLVM_VERSION_STRING main" ;; + Ubuntu_19.04 ) REPO_NAME="deb http://apt.llvm.org/disco/ llvm-toolchain-disco$LLVM_VERSION_STRING main" ;; + Ubuntu_19.10 ) REPO_NAME="deb http://apt.llvm.org/eoan/ llvm-toolchain-eoan$LLVM_VERSION_STRING main" ;; + Ubuntu_20.04 ) REPO_NAME="deb http://apt.llvm.org/focal/ llvm-toolchain-focal$LLVM_VERSION_STRING main" ;; + * ) + echo "Distribution '$DISTRO' in version '$VERSION' is not supported by this script (${DIST_VERSION})." + exit 2 +esac + + +# install everything +wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - +add-apt-repository "${REPO_NAME}" +apt-get update +apt-get install -y clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION From 98839f8876f228224a2e65cc73a552ad2f33d7ff Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 15:33:32 +0300 Subject: [PATCH 04/17] dev --- Dockerfile | 44 ++++++++++++++++++++++++------- install.sh | 14 +++++++--- llvm.sh | 77 ------------------------------------------------------ 3 files changed, 44 insertions(+), 91 deletions(-) delete mode 100755 llvm.sh diff --git a/Dockerfile b/Dockerfile index 8b90cef37845..fc7174e0f39e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,42 @@ -FROM debian:stable +FROM ubuntu:18.04 -RUN mkdir -p /app \ +# mostly taken from https://github.com/ziglang/zig/blob/master/ci/azure/linux_script + + +WORKDIR /app + +RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y update \ - && apt-get install -y curl wget cmake build-essential lsb-release software-properties-common \ - # install llvm, clang, ldd - && wget https://apt.llvm.org/llvm.sh \ - && chmod +x llvm.sh \ - && ./llvm.sh 11 \ - && rm -rf ./llvm.sh \ + && apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git \ && rm -rf /var/lib/apt/lists/* -WORKDIR /app + COPY . /app -RUN /bin/bash install.sh +RUN export DEBIAN_FRONTEND=noninteractive \ + && BUILDDIR="$(pwd)" \ + && sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' \ + && wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ + && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ + && apt-get -y update -q \ + && apt-get remove -y llvm-* \ + && rm -rf /usr/local/* \ + && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy \ + # Make the `zig version` number consistent. + # This will affect the cmake command below. + && git config core.abbrev 9 \ + && export CC=gcc-7 \ + && export CXX=g++-7 \ + && rm -rf /app/build \ + && mkdir -p /app/build \ + && cd /app/build \ + && cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja \ + && ninja install \ + && rm -rf /var/lib/apt/lists/* + +RUN export DEBIAN_FRONTEND=noninteractive \ + && cd /app \ + && ./zig help CMD /bin/bash + diff --git a/install.sh b/install.sh index dfa69304ee29..86fb8704e3d2 100755 --- a/install.sh +++ b/install.sh @@ -10,8 +10,14 @@ shopt -s nullglob globstar export DEBIAN_FRONTEND=noninteractive -mkdir -p build +git config core.abbrev 9 +export CC=gcc-7 +export CXX=g++-7 +rm -rf /app/build +mkdir -p /app/build cd /app/build -cmake .. -make install -cd /app/ +cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja +ninja install +rm -rf /var/lib/apt/lists/* +cd /app +./zig help diff --git a/llvm.sh b/llvm.sh deleted file mode 100755 index 58eef27644b5..000000000000 --- a/llvm.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash -################################################################################ -# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -################################################################################ -# -# This script will install the llvm toolchain on the different -# Debian and Ubuntu versions - -set -eux - -# Check for required tools -needed_binaries=(lsb_release wget add-apt-repository) -missing_binaries=() -for binary in "${needed_binaries[@]}"; do - if ! which $binary &>/dev/null ; then - missing_binaries+=($binary) - fi -done -if [[ ${#missing_binaries[@]} -gt 0 ]] ; then - echo "You are missing some tools this script requires: ${missing_binaries[@]}" - echo "(hint: apt install lsb-release wget software-properties-common)" - exit 4 -fi - -# read optional command line argument -LLVM_VERSION=11 -if [ "$#" -eq 1 ]; then - LLVM_VERSION=$1 -fi - -DISTRO=$(lsb_release -is) -VERSION=$(lsb_release -sr) -DIST_VERSION="${DISTRO}_${VERSION}" - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root!" - exit 1 -fi - -declare -A LLVM_VERSION_PATTERNS -LLVM_VERSION_PATTERNS[9]="-9" -LLVM_VERSION_PATTERNS[10]="-10" -LLVM_VERSION_PATTERNS[11]="-11" -LLVM_VERSION_PATTERNS[12]="" - -if [ ! ${LLVM_VERSION_PATTERNS[$LLVM_VERSION]+_} ]; then - echo "This script does not support LLVM version $LLVM_VERSION" - exit 3 -fi - -LLVM_VERSION_STRING=${LLVM_VERSION_PATTERNS[$LLVM_VERSION]} - -# find the right repository name for the distro and version -case "$DIST_VERSION" in - Debian_9* ) REPO_NAME="deb http://apt.llvm.org/stretch/ llvm-toolchain-stretch$LLVM_VERSION_STRING main" ;; - Debian_10* ) REPO_NAME="deb http://apt.llvm.org/buster/ llvm-toolchain-buster$LLVM_VERSION_STRING main" ;; - Debian_unstable ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; - Debian_testing ) REPO_NAME="deb http://apt.llvm.org/unstable/ llvm-toolchain$LLVM_VERSION_STRING main" ;; - Ubuntu_16.04 ) REPO_NAME="deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial$LLVM_VERSION_STRING main" ;; - Ubuntu_18.04 ) REPO_NAME="deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic$LLVM_VERSION_STRING main" ;; - Ubuntu_18.10 ) REPO_NAME="deb http://apt.llvm.org/cosmic/ llvm-toolchain-cosmic$LLVM_VERSION_STRING main" ;; - Ubuntu_19.04 ) REPO_NAME="deb http://apt.llvm.org/disco/ llvm-toolchain-disco$LLVM_VERSION_STRING main" ;; - Ubuntu_19.10 ) REPO_NAME="deb http://apt.llvm.org/eoan/ llvm-toolchain-eoan$LLVM_VERSION_STRING main" ;; - Ubuntu_20.04 ) REPO_NAME="deb http://apt.llvm.org/focal/ llvm-toolchain-focal$LLVM_VERSION_STRING main" ;; - * ) - echo "Distribution '$DISTRO' in version '$VERSION' is not supported by this script (${DIST_VERSION})." - exit 2 -esac - - -# install everything -wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - -add-apt-repository "${REPO_NAME}" -apt-get update -apt-get install -y clang-$LLVM_VERSION lldb-$LLVM_VERSION lld-$LLVM_VERSION clangd-$LLVM_VERSION From 7e09ba4c350cbc61e267f8e1962dc5e129c0b455 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 15:50:52 +0300 Subject: [PATCH 05/17] dev --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc7174e0f39e..9a7bdfa66b5e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,14 +14,15 @@ RUN export DEBIAN_FRONTEND=noninteractive \ COPY . /app RUN export DEBIAN_FRONTEND=noninteractive \ - && BUILDDIR="$(pwd)" \ && sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' \ && wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ && apt-get -y update -q \ && apt-get remove -y llvm-* \ && rm -rf /usr/local/* \ - && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy \ + && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy + +RUN export DEBIAN_FRONTEND=noninteractive \ # Make the `zig version` number consistent. # This will affect the cmake command below. && git config core.abbrev 9 \ From bc03e532983fb592e946937296b5cb1bd45c4009 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 15:57:14 +0300 Subject: [PATCH 06/17] dev --- Dockerfile | 6 ++---- install.sh | 12 ++++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9a7bdfa66b5e..0324a4e4aa8d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,8 +7,7 @@ WORKDIR /app RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y update \ - && apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git \ - && rm -rf /var/lib/apt/lists/* + && apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git COPY . /app @@ -32,8 +31,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && mkdir -p /app/build \ && cd /app/build \ && cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja \ - && ninja install \ - && rm -rf /var/lib/apt/lists/* + && ninja install RUN export DEBIAN_FRONTEND=noninteractive \ && cd /app \ diff --git a/install.sh b/install.sh index 86fb8704e3d2..e3e3b6c425f3 100755 --- a/install.sh +++ b/install.sh @@ -10,14 +10,14 @@ shopt -s nullglob globstar export DEBIAN_FRONTEND=noninteractive +export DEBIAN_FRONTEND=noninteractive +# Make the `zig version` number consistent. +# This will affect the cmake command below. git config core.abbrev 9 export CC=gcc-7 export CXX=g++-7 -rm -rf /app/build +rm -rf /app/build \ mkdir -p /app/build cd /app/build -cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja -ninja install -rm -rf /var/lib/apt/lists/* -cd /app -./zig help +cmake .. +make install \ No newline at end of file From b05efec627228cec38aafb6a1ffbc34dd8f73e51 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 15:57:34 +0300 Subject: [PATCH 07/17] dev --- install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/install.sh b/install.sh index e3e3b6c425f3..4d87231ff02c 100755 --- a/install.sh +++ b/install.sh @@ -16,6 +16,8 @@ export DEBIAN_FRONTEND=noninteractive git config core.abbrev 9 export CC=gcc-7 export CXX=g++-7 + +# from https://github.com/ziglang/zig/blob/master/README.md#Building-from-Source rm -rf /app/build \ mkdir -p /app/build cd /app/build From 4f2818389da85b75bc46368fd0e32ef11a0e0797 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 16:07:36 +0300 Subject: [PATCH 08/17] dev --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0324a4e4aa8d..973f9d7d429f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ WORKDIR /app RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -y update \ + && rm -rf /usr/local/* \ && apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git @@ -18,7 +19,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ && apt-get -y update -q \ && apt-get remove -y llvm-* \ - && rm -rf /usr/local/* \ && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy RUN export DEBIAN_FRONTEND=noninteractive \ From 458e944f5e9931031371df494c025bf7060a3e17 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 16:48:31 +0300 Subject: [PATCH 09/17] dev --- install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 4d87231ff02c..8230eab420f9 100755 --- a/install.sh +++ b/install.sh @@ -18,7 +18,7 @@ export CC=gcc-7 export CXX=g++-7 # from https://github.com/ziglang/zig/blob/master/README.md#Building-from-Source -rm -rf /app/build \ +rm -rf /app/build mkdir -p /app/build cd /app/build cmake .. From ff06ce934326d939fa51f92a23cdf467e1da89ad Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 21:57:29 +0300 Subject: [PATCH 10/17] dev --- Dockerfile | 5 ++--- build.sh | 28 ++++++++++++++++++++++++++++ install.sh | 23 +++++++++++++++++++---- 3 files changed, 49 insertions(+), 7 deletions(-) create mode 100755 build.sh diff --git a/Dockerfile b/Dockerfile index 973f9d7d429f..acf003d6c9f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' \ && wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ - && apt-get -y update -q \ + && apt-get -y update \ && apt-get remove -y llvm-* \ && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy @@ -34,8 +34,7 @@ RUN export DEBIAN_FRONTEND=noninteractive \ && ninja install RUN export DEBIAN_FRONTEND=noninteractive \ - && cd /app \ - && ./zig help + && cd /app CMD /bin/bash diff --git a/build.sh b/build.sh new file mode 100755 index 000000000000..0d651ac8e604 --- /dev/null +++ b/build.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +if test "$BASH" = "" || "$BASH" -uc "a=();true \"\${a[@]}\"" 2>/dev/null; then + # Bash 4.4, Zsh + set -euo pipefail +else + # Bash 4.3 and older chokes on empty arrays with set -u. + set -eo pipefail +fi +shopt -s nullglob globstar +export DEBIAN_FRONTEND=noninteractive + + +export DEBIAN_FRONTEND=noninteractive +# Make the `zig version` number consistent. +# This will affect the cmake command below. +git config core.abbrev 9 +export CC=gcc-7 +export CXX=g++-7 + +# from https://github.com/ziglang/zig/blob/master/README.md#Building-from-Source +rm -rf /app/build +mkdir -p /app/build +cd /app/build +cmake .. +make install + +# cd /app +# ./zig help diff --git a/install.sh b/install.sh index 8230eab420f9..974f757c6797 100755 --- a/install.sh +++ b/install.sh @@ -10,16 +10,31 @@ shopt -s nullglob globstar export DEBIAN_FRONTEND=noninteractive + +apt-get -y update +rm -rf /usr/local/* +apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git + +export DEBIAN_FRONTEND=noninteractive +sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' +wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - +add-apt-repository -y ppa:ubuntu-toolchain-r/test +apt-get -y update +apt-get remove -y llvm-* +apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy + export DEBIAN_FRONTEND=noninteractive # Make the `zig version` number consistent. # This will affect the cmake command below. git config core.abbrev 9 export CC=gcc-7 export CXX=g++-7 - -# from https://github.com/ziglang/zig/blob/master/README.md#Building-from-Source rm -rf /app/build mkdir -p /app/build cd /app/build -cmake .. -make install \ No newline at end of file +cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja +ninja install + +export DEBIAN_FRONTEND=noninteractive +cd /app +./zig help From 5ddcd2b4cb862d13dea84e0f819783f2f527bd72 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 22:23:15 +0300 Subject: [PATCH 11/17] dev --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index acf003d6c9f6..2838500935e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,3 +38,6 @@ RUN export DEBIAN_FRONTEND=noninteractive \ CMD /bin/bash +# docker-compose build app +# docker-compose run app bash + From a0465648a9612c21b20dd29da4683ed8ddd5d4af Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 23:14:27 +0300 Subject: [PATCH 12/17] complete out the getaffinity error set --- lib/std/os.zig | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 5aa81ac54b15..083f03e22f8f 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4432,15 +4432,27 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void { } } -pub const SchedGetAffinityError = error{PermissionDenied} || UnexpectedError; +pub const SchedGetAffinityError = error{ + /// The calling thread does not have appropriate privileges. + PermissionDenied, + + /// Memory address was invalid. + InvalidAddress, + + /// The affinity bit mask mask contains no processors that are currently physically on the system and permitted to the process. + NoProcessors, + + /// The thread whose ID is pid could not be found. + NoThread, +} || UnexpectedError; pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t { var set: cpu_set_t = undefined; switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) { 0 => return set, - EFAULT => unreachable, - EINVAL => unreachable, - ESRCH => unreachable, + EFAULT => return error.InvalidAddress, + EINVAL => return error.NoProcessors, + ESRCH => return error.NoThread, EPERM => return error.PermissionDenied, else => |err| return unexpectedErrno(err), } From 4a8e1862f6ddddffc8d0d26daf10bb2a27377526 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 23:22:40 +0300 Subject: [PATCH 13/17] add doc string for sched_getaffinity --- lib/std/os.zig | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/std/os.zig b/lib/std/os.zig index 083f03e22f8f..b38fcb56439e 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4446,6 +4446,9 @@ pub const SchedGetAffinityError = error{ NoThread, } || UnexpectedError; +/// Retrieves the affinity mask of a thread. +/// +/// A thread's CPU affinity mask determines the set of CPUs on which it is eligible to run. pub fn sched_getaffinity(pid: pid_t) SchedGetAffinityError!cpu_set_t { var set: cpu_set_t = undefined; switch (errno(system.sched_getaffinity(pid, @sizeOf(cpu_set_t), &set))) { From 812d14fb84ba328d77c611d927715b70300994fb Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 23:58:47 +0300 Subject: [PATCH 14/17] add test for os.sched_getaffinity --- lib/std/os/test.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index 7df05df2cce5..ff0b34c13d02 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -601,3 +601,7 @@ test "getrlimit and setrlimit" { const cpuLimit = try os.getrlimit(.CPU); try os.setrlimit(.CPU, cpuLimit); } + +test "os.sched_getaffinity" { + testing.expectError(error.NoThread, os.sched_getaffinity(std.math.maxInt(i32))); +} From 58836e34c7c32e08ff13bfda5345bef32e12ec10 Mon Sep 17 00:00:00 2001 From: komuW Date: Fri, 30 Oct 2020 23:59:34 +0300 Subject: [PATCH 15/17] rm local development files --- Dockerfile | 43 ------------------------------------------- build.sh | 28 ---------------------------- docker-compose.yml | 8 -------- install.sh | 40 ---------------------------------------- 4 files changed, 119 deletions(-) delete mode 100644 Dockerfile delete mode 100755 build.sh delete mode 100644 docker-compose.yml delete mode 100755 install.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 2838500935e1..000000000000 --- a/Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -FROM ubuntu:18.04 - -# mostly taken from https://github.com/ziglang/zig/blob/master/ci/azure/linux_script - - -WORKDIR /app - -RUN export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y update \ - && rm -rf /usr/local/* \ - && apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git - - -COPY . /app - -RUN export DEBIAN_FRONTEND=noninteractive \ - && sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' \ - && wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - \ - && add-apt-repository -y ppa:ubuntu-toolchain-r/test \ - && apt-get -y update \ - && apt-get remove -y llvm-* \ - && apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy - -RUN export DEBIAN_FRONTEND=noninteractive \ - # Make the `zig version` number consistent. - # This will affect the cmake command below. - && git config core.abbrev 9 \ - && export CC=gcc-7 \ - && export CXX=g++-7 \ - && rm -rf /app/build \ - && mkdir -p /app/build \ - && cd /app/build \ - && cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja \ - && ninja install - -RUN export DEBIAN_FRONTEND=noninteractive \ - && cd /app - -CMD /bin/bash - -# docker-compose build app -# docker-compose run app bash - diff --git a/build.sh b/build.sh deleted file mode 100755 index 0d651ac8e604..000000000000 --- a/build.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -if test "$BASH" = "" || "$BASH" -uc "a=();true \"\${a[@]}\"" 2>/dev/null; then - # Bash 4.4, Zsh - set -euo pipefail -else - # Bash 4.3 and older chokes on empty arrays with set -u. - set -eo pipefail -fi -shopt -s nullglob globstar -export DEBIAN_FRONTEND=noninteractive - - -export DEBIAN_FRONTEND=noninteractive -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git config core.abbrev 9 -export CC=gcc-7 -export CXX=g++-7 - -# from https://github.com/ziglang/zig/blob/master/README.md#Building-from-Source -rm -rf /app/build -mkdir -p /app/build -cd /app/build -cmake .. -make install - -# cd /app -# ./zig help diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 3b839d985f97..000000000000 --- a/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3' -services: - - app: - build: - context: . - volumes: - - ./:/app diff --git a/install.sh b/install.sh deleted file mode 100755 index 974f757c6797..000000000000 --- a/install.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash -if test "$BASH" = "" || "$BASH" -uc "a=();true \"\${a[@]}\"" 2>/dev/null; then - # Bash 4.4, Zsh - set -euo pipefail -else - # Bash 4.3 and older chokes on empty arrays with set -u. - set -eo pipefail -fi -shopt -s nullglob globstar -export DEBIAN_FRONTEND=noninteractive - - - -apt-get -y update -rm -rf /usr/local/* -apt-get -y install software-properties-common curl wget gnupg gnupg1 gnupg2 git - -export DEBIAN_FRONTEND=noninteractive -sh -c 'echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main" >> /etc/apt/sources.list' -wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - -add-apt-repository -y ppa:ubuntu-toolchain-r/test -apt-get -y update -apt-get remove -y llvm-* -apt-get install -y libxml2-dev libclang-11-dev llvm-11 llvm-11-dev liblld-11-dev cmake s3cmd gcc-7 g++-7 ninja-build tidy - -export DEBIAN_FRONTEND=noninteractive -# Make the `zig version` number consistent. -# This will affect the cmake command below. -git config core.abbrev 9 -export CC=gcc-7 -export CXX=g++-7 -rm -rf /app/build -mkdir -p /app/build -cd /app/build -cmake .. -DCMAKE_BUILD_TYPE=Release -GNinja -ninja install - -export DEBIAN_FRONTEND=noninteractive -cd /app -./zig help From 8835be0e14584ec31f714017fd4df01a3e8885e4 Mon Sep 17 00:00:00 2001 From: komuW Date: Sat, 31 Oct 2020 09:55:23 +0300 Subject: [PATCH 16/17] add missing errors to CpuCountError and also zig fmt lib/std/thread.zig --- lib/std/thread.zig | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/std/thread.zig b/lib/std/thread.zig index 330c425dd6f5..75060845248a 100644 --- a/lib/std/thread.zig +++ b/lib/std/thread.zig @@ -63,10 +63,10 @@ pub const Thread = struct { return c.pthread_self(); } else return switch (std.Target.current.os.tag) { - .linux => os.linux.gettid(), - .windows => windows.kernel32.GetCurrentThreadId(), - else => @compileError("Unsupported OS"), - }; + .linux => os.linux.gettid(), + .windows => windows.kernel32.GetCurrentThreadId(), + else => @compileError("Unsupported OS"), + }; } /// Returns the handle of this thread. @@ -479,6 +479,9 @@ pub const Thread = struct { pub const CpuCountError = error{ PermissionDenied, + InvalidAddress, + NoProcessors, + NoThread, SystemResources, Unexpected, }; From f1b6c196cc535c2a794918051f380ae03c33ba2e Mon Sep 17 00:00:00 2001 From: komuW Date: Sun, 1 Nov 2020 16:09:21 +0300 Subject: [PATCH 17/17] skip test of os.sched_getaffinity in non-linux OSes --- lib/std/os/test.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig index ff0b34c13d02..1e12083c9787 100644 --- a/lib/std/os/test.zig +++ b/lib/std/os/test.zig @@ -603,5 +603,10 @@ test "getrlimit and setrlimit" { } test "os.sched_getaffinity" { + // TODO enable for other systems when implemented + // https://github.com/ziglang/zig/issues/6907 + if (builtin.os.tag != .linux) { + return error.SkipZigTest; + } testing.expectError(error.NoThread, os.sched_getaffinity(std.math.maxInt(i32))); }