From abb9002e12775ac5c4764f09252650412409ce30 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sat, 18 Apr 2020 23:07:01 -0700 Subject: [PATCH 1/7] Make build work on Windows --- Makefile | 22 ++++++++++++++++++---- wasi-sdk.cmake | 14 ++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 8293c4840..86e04195b 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,24 @@ ROOT_DIR=${CURDIR} LLVM_PROJ_DIR?=$(ROOT_DIR)/src/llvm-project + +# msys needs any /-prefixed arguments, or =/ containing, to turn into // +# because it tries to path-expand the / into the msys root. // escapes this. +SLASHY_SLASH= + +ifeq ($(OS),Windows_NT) +PREFIX?=c:/wasi-sdk +BASH?=bash -c +ifneq (x$(MSYSTEM),x) +SLASHY_SLASH=/ +endif +else PREFIX?=/opt/wasi-sdk +BASH?= +endif -CLANG_VERSION=$(shell ./llvm_version.sh $(LLVM_PROJ_DIR)) -VERSION:=$(shell ./version.sh) +CLANG_VERSION=$(shell $(BASH) ./llvm_version.sh $(LLVM_PROJ_DIR)) +VERSION:=$(shell $(BASH) ./version.sh) DEBUG_PREFIX_MAP=-fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION) default: build @@ -109,7 +123,7 @@ build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUI cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi \ + -DLIBCXX_LIBDIR_SUFFIX=$(SLASHY_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxx ninja $(NINJA_FLAGS) -v -C build/libcxx # Do the install. @@ -147,7 +161,7 @@ build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT cd build/libcxxabi && cmake -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi \ + -DLIBCXXABI_LIBDIR_SUFFIX=$(SLASHY_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxxabi ninja $(NINJA_FLAGS) -v -C build/libcxxabi # Do the install. diff --git a/wasi-sdk.cmake b/wasi-sdk.cmake index 37dd4524b..e8d41ee01 100644 --- a/wasi-sdk.cmake +++ b/wasi-sdk.cmake @@ -8,10 +8,16 @@ set(CMAKE_SYSTEM_VERSION 1) set(CMAKE_SYSTEM_PROCESSOR wasm32) set(triple wasm32-wasi) -set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang) -set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++) -set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar CACHE STRING "wasi-sdk build") -set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib CACHE STRING "wasi-sdk build") +if(WIN32) + set(WASI_HOST_EXE_SUFFIX ".exe") +else() + set(WASI_HOST_EXE_SUFFIX "") +endif() + +set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX}) +set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar${WASI_HOST_EXE_SUFFIX} CACHE STRING "wasi-sdk build") +set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib${WASI_HOST_EXE_SUFFIX} CACHE STRING "wasi-sdk build") set(CMAKE_C_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") set(CMAKE_CXX_COMPILER_TARGET ${triple} CACHE STRING "wasi-sdk build") set(CMAKE_C_FLAGS "-v" CACHE STRING "wasi-sdk build") From 1bc45a36fb9a809b21c464987d845af123ce0adc Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sat, 18 Apr 2020 23:07:43 -0700 Subject: [PATCH 2/7] re-enable windows build workflow --- .github/workflows/main.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index de0bab062..a423edb67 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,9 +18,7 @@ jobs: os: - ubuntu-latest - macos-latest - # Build still fails on windows - sysroot path passed to compiler-rt - # is incorrect. - # - windows-latest + - windows-latest steps: - uses: actions/checkout@v1 with: From 3307f2d8027db7de38a552854ebf9bd638975bef Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sat, 18 Apr 2020 23:20:03 -0700 Subject: [PATCH 3/7] fix make check --- Makefile | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 86e04195b..903c02a00 100644 --- a/Makefile +++ b/Makefile @@ -4,20 +4,28 @@ ROOT_DIR=${CURDIR} LLVM_PROJ_DIR?=$(ROOT_DIR)/src/llvm-project -# msys needs any /-prefixed arguments, or =/ containing, to turn into // -# because it tries to path-expand the / into the msys root. // escapes this. -SLASHY_SLASH= - +# Windows needs munging ifeq ($(OS),Windows_NT) + PREFIX?=c:/wasi-sdk +# we need to explicitly call bash -c for makefile $(shell ...), otherwise we'll try under +# who knows what BASH?=bash -c + ifneq (x$(MSYSTEM),x) +# msys needs any /-prefixed arguments, or =/ containing, to turn into // +# because it tries to path-expand the / into the msys root. // escapes this. SLASHY_SLASH=/ +# assuming we're running under msys2 (git-bash), PATH needs /c/foo format directories +PATH_PREFIX=$(shell cygpath.exe -u $(PREFIX)) +endif + endif -else + PREFIX?=/opt/wasi-sdk +PATH_PREFIX?=$(PREFIX) +SLASHY_SLASH?= BASH?= -endif CLANG_VERSION=$(shell $(BASH) ./llvm_version.sh $(LLVM_PROJ_DIR)) VERSION:=$(shell $(BASH) ./version.sh) @@ -27,7 +35,7 @@ default: build @echo "Use -fdebug-prefix-map=$(ROOT_DIR)=wasisdk://v$(VERSION)" check: - cd tests && PATH="$(PREFIX)/bin:$$PATH" ./run.sh + cd tests && PATH="$(PATH_PREFIX)/bin:$$PATH" ./run.sh clean: rm -rf build $(PREFIX) From 2bde8b98f720a271fdd4649ee14c5d626f488bdd Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sun, 19 Apr 2020 11:16:08 -0700 Subject: [PATCH 4/7] fix tar_from_installation.sh and dist target --- .gitignore | 1 + Makefile | 2 +- tar_from_installation.sh | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 378eac25d..9d0b71a3c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build +dist diff --git a/Makefile b/Makefile index 903c02a00..6f3082483 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ package: build/package.BUILT build/package.BUILT: build strip mkdir -p dist command -v dpkg-deb >/dev/null && ./deb_from_installation.sh $(shell pwd)/dist || true - ./tar_from_installation.sh $(shell pwd)/dist + ./tar_from_installation.sh "$(shell pwd)/dist" "$(VERSION)" "$(PATH_PREFIX)" touch build/package.BUILT .PHONY: default clean build strip package check diff --git a/tar_from_installation.sh b/tar_from_installation.sh index 2ac2179f7..e5f2e1be3 100755 --- a/tar_from_installation.sh +++ b/tar_from_installation.sh @@ -1,15 +1,19 @@ #!/usr/bin/env bash set -ex +OUTDIR=$PWD/dist +VERSION=`./version.sh` +INDIR=/opt/wasi-sdk + if [ -n "$1" ]; then OUTDIR=$1 -else - OUTDIR=$PWD/dist fi if [ -n "$2" ]; then VERSION="$2" -else - VERSION=`./version.sh` +fi + +if [ -n "$3" ]; then + INDIR="$3" fi PKGDIR=build/wasi-sdk-$VERSION @@ -23,7 +27,7 @@ case "$(uname -s)" in esac rm -rf $PKGDIR -cp -R /opt/wasi-sdk $PKGDIR +cp -R $INDIR $PKGDIR cd build tar czf $OUTDIR/wasi-sdk-$VERSION\-$MACHINE.tar.gz wasi-sdk-$VERSION From a1be37b108c24e2479c4a9f3e7b4de051b130d61 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sun, 19 Apr 2020 15:30:11 -0700 Subject: [PATCH 5/7] Review fixups --- Makefile | 18 +++++++++++------- tar_from_installation.sh | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 6f3082483..1047567bf 100644 --- a/Makefile +++ b/Makefile @@ -12,19 +12,23 @@ PREFIX?=c:/wasi-sdk # who knows what BASH?=bash -c -ifneq (x$(MSYSTEM),x) +ifeq (x$(MSYSTEM),x) +$(error On Windows, this Makefile only works in MSYS2 environments such as git-bash.) +endif + # msys needs any /-prefixed arguments, or =/ containing, to turn into // # because it tries to path-expand the / into the msys root. // escapes this. -SLASHY_SLASH=/ -# assuming we're running under msys2 (git-bash), PATH needs /c/foo format directories +ESCAPE_SLASH=/ + +# assuming we're running under msys2 (git-bash), PATH needs /c/foo format directories (because +# it itself is :-delimited) PATH_PREFIX=$(shell cygpath.exe -u $(PREFIX)) -endif endif PREFIX?=/opt/wasi-sdk PATH_PREFIX?=$(PREFIX) -SLASHY_SLASH?= +ESCAPE_SLASH?= BASH?= CLANG_VERSION=$(shell $(BASH) ./llvm_version.sh $(LLVM_PROJ_DIR)) @@ -131,7 +135,7 @@ build/libcxx.BUILT: build/llvm.BUILT build/compiler-rt.BUILT build/wasi-libc.BUI cd build/libcxx && cmake -G Ninja $(LIBCXX_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DLIBCXX_LIBDIR_SUFFIX=$(SLASHY_SLASH)/wasm32-wasi \ + -DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxx ninja $(NINJA_FLAGS) -v -C build/libcxx # Do the install. @@ -169,7 +173,7 @@ build/libcxxabi.BUILT: build/libcxx.BUILT build/llvm.BUILT cd build/libcxxabi && cmake -G Ninja $(LIBCXXABI_CMAKE_FLAGS) \ -DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP)" \ -DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP)" \ - -DLIBCXXABI_LIBDIR_SUFFIX=$(SLASHY_SLASH)/wasm32-wasi \ + -DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \ $(LLVM_PROJ_DIR)/libcxxabi ninja $(NINJA_FLAGS) -v -C build/libcxxabi # Do the install. diff --git a/tar_from_installation.sh b/tar_from_installation.sh index e5f2e1be3..e6cc0d0f2 100755 --- a/tar_from_installation.sh +++ b/tar_from_installation.sh @@ -1,19 +1,22 @@ #!/usr/bin/env bash set -ex -OUTDIR=$PWD/dist -VERSION=`./version.sh` -INDIR=/opt/wasi-sdk if [ -n "$1" ]; then OUTDIR=$1 +else + OUTDIR=$PWD/dist fi if [ -n "$2" ]; then VERSION="$2" +else + VERSION=`./version.sh` fi if [ -n "$3" ]; then - INDIR="$3" + INSTALL_DIR="$3" +else + INSTALL_DIR=/opt/wasi-sdk fi PKGDIR=build/wasi-sdk-$VERSION @@ -26,8 +29,13 @@ case "$(uname -s)" in *) MACHINE="UNKNOWN" esac +if [ ! -d $INSTALL_DIR ] ; then + echo "Directory $INSTALL_DIR doesn't exist. Nothing to copy from." + exit 1 +fi + rm -rf $PKGDIR -cp -R $INDIR $PKGDIR +cp -R $INSTALL_DIR $PKGDIR cd build tar czf $OUTDIR/wasi-sdk-$VERSION\-$MACHINE.tar.gz wasi-sdk-$VERSION From 305fff0aa36f950771af55b3ec8c1a366fef49fd Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Sun, 19 Apr 2020 15:35:16 -0700 Subject: [PATCH 6/7] No -j4 on Windows --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a423edb67..c4cc7b56e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: run: sudo make -j4 package if: matrix.os != 'windows-latest' - name: Build - run: make -j4 package + run: make package shell: bash if: matrix.os == 'windows-latest' - name: Run the testsuite From 8a6ddee09cef5a3e229b77d3f832a689ce492f53 Mon Sep 17 00:00:00 2001 From: Vladimir Vukicevic Date: Mon, 20 Apr 2020 10:35:31 -0700 Subject: [PATCH 7/7] Get rid of -j4 everywhere in Makefile --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c4cc7b56e..c0e770e0f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,7 +33,7 @@ jobs: run: sudo apt install ninja-build if: matrix.os == 'ubuntu-latest' - name: Build - run: sudo make -j4 package + run: sudo make package if: matrix.os != 'windows-latest' - name: Build run: make package