Skip to content

Commit

Permalink
msvcenv-native: Extract the target arch from msvcenv.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mstorsjo committed Jun 16, 2023
1 parent 6c9a11a commit 450012b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,18 @@ jobs:
aarch64) msvcarch=arm64 ;;
esac
(BIN=$(pwd)/msvc/bin/$msvcarch . ./msvcenv-native.sh
clang-cl --target=$arch-windows-msvc test/hello.c -c -Fohello-$arch.obj
clang-cl --target=$TARGET_TRIPLE test/hello.c -c -Fohello-$arch.obj
lld-link hello-$arch.obj -out:hello-$arch.exe
)
done
ls -l *.exe
- name: Test building with CMake
run: |
for arch in i686 x86_64 armv7 aarch64; do
for arch in x86 x64 arm arm64; do
mkdir test/build-$arch
cd test/build-$arch
case $arch in
i*86) msvcarch=x86 ;;
x86_64) msvcarch=x64 ;;
arm*) msvcarch=arm ;;
aarch64) msvcarch=arm64 ;;
esac
(BIN=$(pwd)/../../msvc/bin/$msvcarch . ../../msvcenv-native.sh
CC="clang-cl --target=$arch-windows-msvc" CXX="clang-cl --target=$arch-windows-msvc" RC="llvm-rc" cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_MT=/usr/bin/llvm-mt
(BIN=$(pwd)/../../msvc/bin/$arch . ../../msvcenv-native.sh
CC="clang-cl --target=$TARGET_TRIPLE" CXX="clang-cl --target=$TARGET_TRIPLE" RC="llvm-rc" cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_MT=/usr/bin/llvm-mt
ninja -v
)
cd ../..
Expand Down
14 changes: 4 additions & 10 deletions Dockerfile.clang
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ ENV PATH=/opt/clang/bin:$PATH
COPY test/hello.c ./

RUN \
for arch in i686 x86_64 armv7 aarch64; do \
case $arch in \
i*86) msvcarch=x86 ;; \
x86_64) msvcarch=x64 ;; \
arm*) msvcarch=arm ;; \
aarch64) msvcarch=arm64 ;; \
esac; \
(BIN=/opt/msvc/bin/$msvcarch . /opt/msvc/msvcenv-native.sh && \
clang-cl --target=$arch-windows-msvc hello.c -fuse-ld=lld -Fehello-$arch.exe && \
clang --target=$arch-windows-msvc hello.c -fuse-ld=lld -o hello-$arch.exe \
for arch in x86 x64 arm arm64; do \
(BIN=/opt/msvc/bin/$arch . /opt/msvc/msvcenv-native.sh && \
clang-cl --target=$TARGET_TRIPLE hello.c -fuse-ld=lld -Fehello-$arch.exe && \
clang --target=$TARGET_TRIPLE hello.c -fuse-ld=lld -o hello-$arch.exe \
) || exit 1; \
done
8 changes: 8 additions & 0 deletions msvcenv-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ else
else
export INCLUDE="$(bash -c ". $ENV && /bin/echo \"\$INCLUDE\"" | sed s/z://g | sed 's/\\/\//g')"
export LIB="$(bash -c ". $ENV && /bin/echo \"\$LIB\"" | sed s/z://g | sed 's/\\/\//g')"
MSVCARCH="$(bash -c ". $ENV && /bin/echo \"\$ARCH\"")"
case $MSVCARCH in
x86) TARGET_ARCH=i686 ;;
x64) TARGET_ARCH=x86_64 ;;
arm) TARGET_ARCH=armv7 ;;
arm64) TARGET_ARCH=aarch64 ;;
esac
TARGET_TRIPLE=$TARGET_ARCH-windows-msvc
fi
fi

0 comments on commit 450012b

Please sign in to comment.