Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] Support for zig compiler #2280

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/zig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Zig compiler
on:
push:
branches: [ '*' ]
pull_request:
branches: [ '*' ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
zig:
if: github.repository_owner == 'aws'
runs-on: ${{ matrix.os.name }}
strategy:
fail-fast: false
matrix:
os:
- name: windows-latest
target: x86_64-windows
- name: ubuntu-latest
target: x86_64-linux
- name: macos-latest
target: aarch64-macos
steps:
- name: Install NASM
uses: ilammy/[email protected]
- name: Checkout
uses: actions/checkout@v4
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- uses: actions/setup-go@v4
with:
go-version: '>= 1.18'
- name: Install zigcc
uses: jiacai2050/[email protected]
with:
zig-version: 0.14.0
- name: Locate zig not on Windows
if: matrix.os.name != 'windows-latest'
shell: bash
run: |
cat <<'EOF' > ${PWD}/zig-cc
#!/bin/bash
zig cc "$@"
EOF
chmod +x ${PWD}/zig-cc
cat <<'EOF' > ${PWD}/zig-c++
#!/bin/bash
zig c++ "$@"
EOF
chmod +x ${PWD}/zig-c++
echo "ZIGCC=${PWD}/zig-cc" >> $GITHUB_ENV
echo "ZIGCXX=${PWD}/zig-c++" >> $GITHUB_ENV
- name: Locate zig on Windows
if: matrix.os.name == 'windows-latest'
shell: bash
run: |
ZIGCC="python3 $(cygpath -m $(which zigcc))"
ZIGCXX="python3 $(cygpath -m $(which zigcxx))"
echo "ZIGCC=${ZIGCC}" >> $GITHUB_ENV
echo "ZIGCXX=${ZIGCXX}" >> $GITHUB_ENV
- name: Create toolchain
shell: bash
run: |
cat <<EOF > ./toolchain.cmake
set(CMAKE_C_COMPILER ${ZIGCC})
set(CMAKE_C_COMPILER_TARGET ${{ matrix.os.target }})
set(CMAKE_CXX_COMPILER ${ZIGCXX})
set(CMAKE_CXX_COMPILER_TARGET ${{ matrix.os.target }})
set(CMAKE_ASM_COMPILER ${ZIGCC})
set(CMAKE_ASM_COMPILER_TARGET ${{ matrix.os.target }})
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_MESSAGE_LOG_LEVEL DEBUG)
EOF
- name: Setup CMake
shell: bash
run: |
printenv | sort
which zigcc
which zigcxx
cat ./toolchain.cmake
cmake '.' -B ./build -G Ninja -DCMAKE_TOOLCHAIN_FILE=./toolchain.cmake -DCMAKE_BUILD_TYPE=Release
- name: Build Project
shell: bash
run: |
cmake --build ./build --target run_tests --verbose
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ if(GCC OR CLANG)
endif()
endif()

if(MINGW)
if(MINGW AND NOT CLANG)
# Some MinGW compilers set _WIN32_WINNT to an older version (Windows Server 2003)
# See: https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt?view=msvc-170
# Support Windows 7 and later.
Expand Down
22 changes: 16 additions & 6 deletions crypto/fipsmodule/rand/urandom.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
#endif // OPENSSL_LINUX

#if defined(OPENSSL_APPLE)
#if __has_include(<CommonCrypto/CommonRandom.h>)
#define AWS_LC_HAVE_COMMON_CRYPTO
#include <CommonCrypto/CommonRandom.h>
#else
#define AWS_LC_USE_ARC4RANDOM
#endif
#endif

#if defined(OPENSSL_FREEBSD)
Expand All @@ -80,6 +85,10 @@
#endif

#if defined(OPENSSL_OPENBSD)
#define AWS_LC_USE_ARC4RANDOM
#endif

#if defined(AWS_LC_USE_ARC4RANDOM)
#include <stdlib.h>
#endif

Expand Down Expand Up @@ -250,16 +259,16 @@ static void init_once(void) {
}
#endif // USE_NR_getrandom

#if defined(OPENSSL_APPLE)
#if defined(AWS_LC_HAVE_COMMON_CRYPTO)
// To get system randomness on MacOS and iOS we use |CCRandomGenerateBytes|
// function provided by Apple rather than /dev/urandom or |getentropy|
// function which is available on MacOS but not on iOS.
return;
#endif

#if defined(OPENSSL_OPENBSD)
#if defined(AWS_LC_USE_ARC4RANDOM)
// To get system randomness on OpenBSD we use |arc4random_buf| function
// which is recommended to use for C APIs rather then /dev/urandom.
// which is recommended to use for C APIs rather than /dev/urandom.
// See https://man.openbsd.org/arc4random.3
return;
#endif
Expand Down Expand Up @@ -350,7 +359,8 @@ static void wait_for_entropy(void) {
}

#if defined(BORINGSSL_FIPS) && !defined(URANDOM_BLOCKS_FOR_ENTROPY) && \
!(defined(OPENSSL_APPLE) || defined(OPENSSL_OPENBSD)) // On MacOS, iOS, and OpenBSD we don't use /dev/urandom.
!(defined(AWS_LC_HAVE_COMMON_CRYPTO) || defined(AWS_LC_USE_ARC4RANDOM))
// On MacOS, iOS, and OpenBSD we don't use /dev/urandom.

// In FIPS mode on platforms where urandom doesn't block at startup, we ensure
// that the kernel has sufficient entropy before continuing. This is
Expand Down Expand Up @@ -388,7 +398,7 @@ static int fill_with_entropy(uint8_t *out, size_t len, int block, int seed) {
return 1;
}

#if defined(OPENSSL_APPLE)
#if defined(AWS_LC_HAVE_COMMON_CRYPTO)
// To get system randomness on MacOS and iOS we use |CCRandomGenerateBytes|
// rather than |getentropy| and /dev/urandom.
if (CCRandomGenerateBytes(out, len) == kCCSuccess) {
Expand All @@ -399,7 +409,7 @@ static int fill_with_entropy(uint8_t *out, size_t len, int block, int seed) {
}
#endif

#if defined(OPENSSL_OPENBSD)
#if defined(AWS_LC_USE_ARC4RANDOM)
// Return value is void, no error to check
arc4random_buf(out, len);
return 1;
Expand Down
Loading