Skip to content

Commit 21f1861

Browse files
authored
Improve handling of CFLAGS (#712)
1 parent 6178df0 commit 21f1861

File tree

12 files changed

+468
-133
lines changed

12 files changed

+468
-133
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0 OR ISC
3+
4+
FROM ubuntu:24.04
5+
6+
ARG CMAKE_VERSION
7+
ARG CMAKE_DOWNLOAD_URL
8+
ARG CMAKE_SHA256
9+
10+
VOLUME ["/awslc"]
11+
12+
RUN apt-get update && \
13+
apt-get install -y ca-certificates build-essential cmake git wget curl jq unzip clang sudo golang zlib1g-dev libcurl4-openssl-dev libarchive-dev liblzma-dev xz-utils && \
14+
apt-get autoremove --purge -y && \
15+
apt-get clean && \
16+
apt-get autoclean && \
17+
rm -rf /var/lib/apt/lists/* && \
18+
rm -rf /tmp/*
19+
20+
RUN mkdir /cmake
21+
22+
COPY cmake_build.sh /
23+
COPY aws_lc_rs_build.sh /
24+
COPY entry.sh /
25+
26+
WORKDIR /cmake
27+
28+
RUN curl -L -o source.tar.gz "${CMAKE_DOWNLOAD_URL}" && \
29+
echo "${CMAKE_SHA256} source.tar.gz" | sha256sum -c - && \
30+
mkdir source && \
31+
tar -x -f source.tar.gz -v --strip-components=1 -C source
32+
33+
WORKDIR /cmake/source
34+
35+
RUN /cmake_build.sh
36+
37+
RUN useradd -m docker
38+
USER docker
39+
RUN cd "${HOME}" && \
40+
git config --global --add safe.directory '*' && \
41+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > ./rustup.sh && \
42+
chmod +x ./rustup.sh && \
43+
./rustup.sh -y && \
44+
. "${HOME}/.cargo/env" && \
45+
cargo install --locked bindgen-cli && \
46+
rustup component add rustfmt clippy && \
47+
rm ./rustup.sh
48+
49+
ENV AWS_LC_SYS_CMAKE_BUILDER=1
50+
51+
ENTRYPOINT ["/entry.sh"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0 OR ISC
5+
6+
set -ex -o pipefail
7+
8+
echo "Building with CMake Version: $(cmake --version)"
9+
FIPS_BUILD=1
10+
if cmake --version | grep -q " 4."; then
11+
echo "CMake version is 4.x, skipping FIPS build"
12+
FIPS_BUILD=0
13+
fi
14+
15+
. "${HOME}/.cargo/env"
16+
SRC_DIR="${SRC_DIR:-/aws_lc_rs}"
17+
18+
19+
pushd "${SRC_DIR}"
20+
cargo clean
21+
cargo test -p aws-lc-rs --features=unstable
22+
cargo clean
23+
if [ ${FIPS_BUILD} -eq 1 ]; then
24+
cargo test -p aws-lc-rs --features=unstable,fips
25+
cargo clean
26+
fi
27+
cargo test -p aws-lc-rs --release --features=unstable
28+
cargo clean
29+
if [ ${FIPS_BUILD} -eq 1 ]; then
30+
cargo test -p aws-lc-rs --release --features=unstable,fips
31+
cargo clean
32+
fi
33+
34+
35+
popd # ${BUILD_DIR}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0 OR ISC
5+
6+
set -ex -o pipefail
7+
8+
echo "Building CMake Version: ${CMAKE_VERSION:-unknown}"
9+
10+
NUM_CPU_THREADS=$(grep -c ^processor /proc/cpuinfo)
11+
12+
# At the moment this works fine for all versions, in the future build logic can be modified to
13+
# look at it ${CMAKE_VERSION}.
14+
./configure --prefix=/opt/cmake --system-curl --system-libarchive
15+
make -j"${NUM_CPU_THREADS}"
16+
make install
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
# SPDX-License-Identifier: Apache-2.0 OR ISC
5+
6+
set -ex -o pipefail
7+
8+
export PATH="/opt/cmake/bin:${PATH}"
9+
10+
/aws_lc_rs_build.sh "${argv[@]}"

.github/workflows/cmake.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CMake Compatability
2+
on:
3+
push:
4+
branches: [ '*' ]
5+
pull_request:
6+
branches: [ '*' ]
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.ref_name }}
9+
cancel-in-progress: true
10+
env:
11+
DOCKER_BUILDKIT: 1
12+
GOPROXY: https://proxy.golang.org,direct
13+
jobs:
14+
cmake:
15+
if: github.repository_owner == 'aws'
16+
name: CMake ${{ matrix.cmake.version}} build with ${{ matrix.generator}}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
cmake:
21+
- { version: "3.5", url: "https://cmake.org/files/v3.5/cmake-3.5.0.tar.gz", hash: "92c83ad8a4fd6224cf6319a60b399854f55b38ebe9d297c942408b792b1a9efa" }
22+
- { version: "3.28", url: "https://cmake.org/files/v3.28/cmake-3.28.1.tar.gz", hash: "15e94f83e647f7d620a140a7a5da76349fc47a1bfed66d0f5cdee8e7344079ad" }
23+
- { version: "4.0", url: "https://cmake.org/files/v4.0/cmake-4.0.0-rc3.tar.gz", hash: "d1ae66637fb083efde5c12b45a76ab9bcd419970979c93b14a0d0d21eb8c6c08" }
24+
runs-on: ubuntu-latest
25+
env:
26+
DOCKER_BUILDKIT: 1
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: "recursive"
31+
- name: Build Docker Image
32+
working-directory: .github/docker_images/cmake_build_versions
33+
run: |
34+
docker build -t "cmake-${{ matrix.cmake.version }}" --build-arg CMAKE_VERSION=${{ matrix.cmake.version }} --build-arg CMAKE_DOWNLOAD_URL=${{ matrix.cmake.url }} --build-arg CMAKE_SHA256=${{ matrix.cmake.hash }} .
35+
- name: Test
36+
run: |
37+
docker run -v "${{ github.workspace }}:/aws_lc_rs" "cmake-${{ matrix.cmake.version }}"

.github/workflows/integration.yml

+22
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@ jobs:
6565
run: |
6666
./scripts/run-rustls-integration.sh
6767
68+
windows-debug-crt-static-test:
69+
if: github.repository_owner == 'aws'
70+
name: "Windows debug w/ crt-static Test"
71+
runs-on: windows-latest
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
os: [ windows-latest ]
76+
steps:
77+
- uses: actions/checkout@v3
78+
with:
79+
submodules: 'recursive'
80+
- uses: dtolnay/rust-toolchain@stable
81+
id: toolchain
82+
- name: Set Rust toolchain override
83+
run: rustup override set ${{ steps.toolchain.outputs.name }}
84+
- name: run-windows-debug-crt-static-test
85+
working-directory: ./aws-lc-rs
86+
shell: bash
87+
run: |
88+
./scripts/run-windows-debug-crt-static-test.sh
89+
6890
links-crate-tests:
6991
if: github.repository_owner == 'aws'
7092
name: sys crate tests

.gitmodules

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
[submodule "aws-lc-fips-sys/aws-lc"]
66
path = aws-lc-fips-sys/aws-lc
77
url = https://github.com/aws/aws-lc.git
8-
branch = fips-2022-11-02
8+
branch = fips-2024-09-27

aws-lc-fips-sys/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0 OR ISC
33

4-
cmake_minimum_required(VERSION 3.0)
4+
cmake_minimum_required(VERSION 3.5...3.31)
5+
6+
if(CMAKE_VERSION VERSION_GREATER "3.14")
7+
# https://cmake.org/cmake/help/latest/policy/CMP0091.html
8+
# In CMake 3.14 and below, MSVC runtime library selection flags are added to the default CMAKE_<LANG>_FLAGS_<CONFIG>
9+
# cache entries by CMake automatically.
10+
cmake_policy(SET CMP0091 OLD)
11+
endif()
512

613
project(AWS_LC_RUST NONE)
714
enable_language(C)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash -exu
2+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
# SPDX-License-Identifier: Apache-2.0 OR ISC
4+
5+
SRC_ROOT="${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)}/aws-lc-rs"
6+
7+
case `uname -s` in
8+
CYGWIN*) echo Cygwin;;
9+
MINGW*) echo MinGw;;
10+
MSYS_NT*) echo MSys;;
11+
*) echo Unknown OS: `uname -s`; exit 1;;
12+
esac
13+
14+
TMP_DIR=`mktemp -d`
15+
16+
pushd "${TMP_DIR}"
17+
cargo new --bin aws-lc-rs-test
18+
pushd aws-lc-rs-test
19+
20+
cargo add aws-lc-rs rustls rustls-platform-verifier
21+
cat << EOF >> Cargo.toml
22+
[profile.release]
23+
debug = "limited"
24+
25+
[patch.crates-io]
26+
"aws-lc-rs" = { path = "${SRC_ROOT//\\/\/}" }
27+
EOF
28+
29+
mkdir -p .cargo
30+
cat << EOF > .cargo/config.toml
31+
[target.'cfg(target_os = "windows")']
32+
rustflags = ["-C", "target-feature=+crt-static"]
33+
EOF
34+
35+
cargo update
36+
cargo build --release
37+
38+
popd
39+
popd

aws-lc-sys/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0 OR ISC
33

4-
cmake_minimum_required(VERSION 3.0)
4+
cmake_minimum_required(VERSION 3.5...3.31)
5+
6+
if(CMAKE_VERSION VERSION_GREATER "3.14")
7+
# https://cmake.org/cmake/help/latest/policy/CMP0091.html
8+
# In CMake 3.14 and below, MSVC runtime library selection flags are added to the default CMAKE_<LANG>_FLAGS_<CONFIG>
9+
# cache entries by CMake automatically.
10+
cmake_policy(SET CMP0091 OLD)
11+
endif()
512

613
project(AWS_LC_RUST NONE)
714
enable_language(C)

0 commit comments

Comments
 (0)