From 66b977f88eea1fe202dbd21cd8cf827e6f15cc4e Mon Sep 17 00:00:00 2001 From: Justin W Smith <103147162+justsmth@users.noreply.github.com> Date: Fri, 2 Feb 2024 08:07:48 -0500 Subject: [PATCH] Script working on Mac --- .../builder/cc/x86_64-apple-darwin.toml | 111 +++++++++--------- aws-lc-sys/builder/cmake_builder.rs | 14 ++- scripts/build/generate_build_toml.sh | 82 ++++++++----- 3 files changed, 122 insertions(+), 85 deletions(-) diff --git a/aws-lc-sys/builder/cc/x86_64-apple-darwin.toml b/aws-lc-sys/builder/cc/x86_64-apple-darwin.toml index 0081eb5c48a..2d710033a4b 100644 --- a/aws-lc-sys/builder/cc/x86_64-apple-darwin.toml +++ b/aws-lc-sys/builder/cc/x86_64-apple-darwin.toml @@ -1,3 +1,8 @@ +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 OR ISC +# +# Generated-by: ./scripts/build/generate_build_toml.sh + [[Library]] name = "crypto" flags = [] @@ -23,13 +28,13 @@ sources = [ "crypto/asn1/asn_pack.c", "crypto/asn1/f_int.c", "crypto/asn1/f_string.c", + "crypto/asn1/posix_time.c", "crypto/asn1/tasn_dec.c", "crypto/asn1/tasn_enc.c", "crypto/asn1/tasn_fre.c", "crypto/asn1/tasn_new.c", "crypto/asn1/tasn_typ.c", "crypto/asn1/tasn_utl.c", - "crypto/asn1/posix_time.c", "crypto/base64/base64.c", "crypto/bio/bio.c", "crypto/bio/bio_mem.c", @@ -53,11 +58,11 @@ sources = [ "crypto/chacha/chacha.c", "crypto/cipher_extra/cipher_extra.c", "crypto/cipher_extra/derive_key.c", + "crypto/cipher_extra/e_aes_cbc_hmac_sha1.c", + "crypto/cipher_extra/e_aes_cbc_hmac_sha256.c", "crypto/cipher_extra/e_aesctrhmac.c", "crypto/cipher_extra/e_aesgcmsiv.c", "crypto/cipher_extra/e_chacha20poly1305.c", - "crypto/cipher_extra/e_aes_cbc_hmac_sha1.c", - "crypto/cipher_extra/e_aes_cbc_hmac_sha256.c", "crypto/cipher_extra/e_des.c", "crypto/cipher_extra/e_null.c", "crypto/cipher_extra/e_rc2.c", @@ -70,20 +75,29 @@ sources = [ "crypto/curve25519/curve25519_nohw.c", "crypto/curve25519/curve25519_s2n_bignum_asm.c", "crypto/curve25519/spake25519.c", + "crypto/decrepit/bio/base64_bio.c", + "crypto/decrepit/blowfish/blowfish.c", + "crypto/decrepit/cast/cast.c", + "crypto/decrepit/cast/cast_tables.c", + "crypto/decrepit/cfb/cfb.c", + "crypto/decrepit/dh/dh_decrepit.c", + "crypto/decrepit/evp/evp_do_all.c", + "crypto/decrepit/ripemd/ripemd.c", + "crypto/decrepit/rsa/rsa_decrepit.c", + "crypto/decrepit/x509/x509_decrepit.c", "crypto/des/des.c", - "crypto/dh_extra/params.c", "crypto/dh_extra/dh_asn1.c", + "crypto/dh_extra/params.c", "crypto/digest_extra/digest_extra.c", "crypto/dsa/dsa.c", "crypto/dsa/dsa_asn1.c", - "crypto/ecdh_extra/ecdh_extra.c", - "crypto/ecdsa_extra/ecdsa_asn1.c", "crypto/ec_extra/ec_asn1.c", "crypto/ec_extra/ec_derive.c", "crypto/ec_extra/hash_to_curve.c", - "crypto/err/err.c", - "generated-src/err_data.c", + "crypto/ecdh_extra/ecdh_extra.c", + "crypto/ecdsa_extra/ecdsa_asn1.c", "crypto/engine/engine.c", + "crypto/err/err.c", "crypto/evp_extra/evp_asn1.c", "crypto/evp_extra/p_dsa_asn1.c", "crypto/evp_extra/p_ec_asn1.c", @@ -92,23 +106,25 @@ sources = [ "crypto/evp_extra/p_hmac_asn1.c", "crypto/evp_extra/p_kem.c", "crypto/evp_extra/p_kem_asn1.c", + "crypto/evp_extra/p_methods.c", "crypto/evp_extra/p_rsa_asn1.c", "crypto/evp_extra/p_x25519.c", "crypto/evp_extra/p_x25519_asn1.c", - "crypto/evp_extra/p_methods.c", "crypto/evp_extra/print.c", "crypto/evp_extra/scrypt.c", "crypto/evp_extra/sign.c", "crypto/ex_data.c", + "crypto/fipsmodule/bcm.c", + "crypto/fipsmodule/cpucap/cpucap.c", "crypto/hpke/hpke.c", "crypto/hrss/hrss.c", "crypto/kem/kem.c", "crypto/kem/kem_methods.c", + "crypto/kyber/kem_kyber.c", + "crypto/kyber/kyber1024r3_ref.c", "crypto/kyber/kyber512r3_ref.c", "crypto/kyber/kyber768r3_ref.c", - "crypto/kyber/kyber1024r3_ref.c", "crypto/kyber/pqcrystals_kyber_ref_common/fips202.c", - "crypto/kyber/kem_kyber.c", "crypto/lhash/lhash.c", "crypto/mem.c", "crypto/obj/obj.c", @@ -131,21 +147,21 @@ sources = [ "crypto/pem/pem_xaux.c", "crypto/pkcs7/pkcs7.c", "crypto/pkcs7/pkcs7_x509.c", + "crypto/pkcs8/p5_pbev2.c", "crypto/pkcs8/pkcs8.c", "crypto/pkcs8/pkcs8_x509.c", - "crypto/pkcs8/p5_pbev2.c", "crypto/poly1305/poly1305_vec.c", "crypto/pool/pool.c", "crypto/rand_extra/forkunsafe.c", - "crypto/rand_extra/rand_extra.c", "crypto/rand_extra/pq_custom_randombytes.c", + "crypto/rand_extra/rand_extra.c", "crypto/rc4/rc4.c", "crypto/refcount_lock.c", "crypto/rsa_extra/rsa_asn1.c", - "crypto/rsa_extra/rsassa_pss_asn1.c", "crypto/rsa_extra/rsa_print.c", - "crypto/stack/stack.c", + "crypto/rsa_extra/rsassa_pss_asn1.c", "crypto/siphash/siphash.c", + "crypto/stack/stack.c", "crypto/thread.c", "crypto/thread_pthread.c", "crypto/trust_token/pmbtoken.c", @@ -223,28 +239,16 @@ sources = [ "crypto/x509v3/v3_purp.c", "crypto/x509v3/v3_skey.c", "crypto/x509v3/v3_utl.c", - "crypto/decrepit/bio/base64_bio.c", - "crypto/decrepit/blowfish/blowfish.c", - "crypto/decrepit/cast/cast.c", - "crypto/decrepit/cast/cast_tables.c", - "crypto/decrepit/cfb/cfb.c", - "crypto/decrepit/dh/dh_decrepit.c", - "crypto/decrepit/evp/evp_do_all.c", - "crypto/decrepit/ripemd/ripemd.c", - "crypto/decrepit/rsa/rsa_decrepit.c", - "crypto/decrepit/x509/x509_decrepit.c", + "generated-src/err_data.c", "generated-src/mac-x86_64/crypto/chacha/chacha-x86_64.S", - "generated-src/mac-x86_64/crypto/cipher_extra/chacha20_poly1305_x86_64.S", "generated-src/mac-x86_64/crypto/cipher_extra/aes128gcmsiv-x86_64.S", "generated-src/mac-x86_64/crypto/cipher_extra/aesni-sha1-x86_64.S", "generated-src/mac-x86_64/crypto/cipher_extra/aesni-sha256-x86_64.S", - "generated-src/mac-x86_64/crypto/test/trampoline-x86_64.S", - "crypto/fipsmodule/bcm.c", - "crypto/fipsmodule/cpucap/cpucap.c", + "generated-src/mac-x86_64/crypto/cipher_extra/chacha20_poly1305_x86_64.S", "generated-src/mac-x86_64/crypto/fipsmodule/aesni-gcm-avx512.S", "generated-src/mac-x86_64/crypto/fipsmodule/aesni-gcm-x86_64.S", - "generated-src/mac-x86_64/crypto/fipsmodule/aesni-xts-avx512.S", "generated-src/mac-x86_64/crypto/fipsmodule/aesni-x86_64.S", + "generated-src/mac-x86_64/crypto/fipsmodule/aesni-xts-avx512.S", "generated-src/mac-x86_64/crypto/fipsmodule/ghash-ssse3-x86_64.S", "generated-src/mac-x86_64/crypto/fipsmodule/ghash-x86_64.S", "generated-src/mac-x86_64/crypto/fipsmodule/md5-x86_64.S", @@ -256,30 +260,9 @@ sources = [ "generated-src/mac-x86_64/crypto/fipsmodule/sha256-x86_64.S", "generated-src/mac-x86_64/crypto/fipsmodule/sha512-x86_64.S", "generated-src/mac-x86_64/crypto/fipsmodule/vpaes-x86_64.S", - "generated-src/mac-x86_64/crypto/fipsmodule/x86_64-mont5.S", "generated-src/mac-x86_64/crypto/fipsmodule/x86_64-mont.S", - "third_party/s2n-bignum/x86_att/p384/bignum_add_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_sub_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_neg_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_tomont_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_deamont_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_montmul_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_montmul_p384_alt.S", - "third_party/s2n-bignum/x86_att/p384/bignum_montsqr_p384.S", - "third_party/s2n-bignum/x86_att/p384/bignum_montsqr_p384_alt.S", - "third_party/s2n-bignum/x86_att/p384/bignum_nonzero_6.S", - "third_party/s2n-bignum/x86_att/p384/bignum_littleendian_6.S", - "third_party/s2n-bignum/x86_att/p521/bignum_add_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_sub_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_neg_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_mul_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_mul_p521_alt.S", - "third_party/s2n-bignum/x86_att/p521/bignum_sqr_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_sqr_p521_alt.S", - "third_party/s2n-bignum/x86_att/p521/bignum_tolebytes_p521.S", - "third_party/s2n-bignum/x86_att/p521/bignum_fromlebytes_p521.S", - "third_party/s2n-bignum/x86_att/p384/bignum_tomont_p384_alt.S", - "third_party/s2n-bignum/x86_att/p384/bignum_deamont_p384_alt.S", + "generated-src/mac-x86_64/crypto/fipsmodule/x86_64-mont5.S", + "generated-src/mac-x86_64/crypto/test/trampoline-x86_64.S", "third_party/s2n-bignum/x86_att/curve25519/bignum_madd_n25519.S", "third_party/s2n-bignum/x86_att/curve25519/bignum_madd_n25519_alt.S", "third_party/s2n-bignum/x86_att/curve25519/bignum_mod_n25519.S", @@ -295,4 +278,26 @@ sources = [ "third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmulbase_alt.S", "third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmuldouble.S", "third_party/s2n-bignum/x86_att/curve25519/edwards25519_scalarmuldouble_alt.S", + "third_party/s2n-bignum/x86_att/p384/bignum_add_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_deamont_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_deamont_p384_alt.S", + "third_party/s2n-bignum/x86_att/p384/bignum_littleendian_6.S", + "third_party/s2n-bignum/x86_att/p384/bignum_montmul_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_montmul_p384_alt.S", + "third_party/s2n-bignum/x86_att/p384/bignum_montsqr_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_montsqr_p384_alt.S", + "third_party/s2n-bignum/x86_att/p384/bignum_neg_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_nonzero_6.S", + "third_party/s2n-bignum/x86_att/p384/bignum_sub_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_tomont_p384.S", + "third_party/s2n-bignum/x86_att/p384/bignum_tomont_p384_alt.S", + "third_party/s2n-bignum/x86_att/p521/bignum_add_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_fromlebytes_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_mul_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_mul_p521_alt.S", + "third_party/s2n-bignum/x86_att/p521/bignum_neg_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_sqr_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_sqr_p521_alt.S", + "third_party/s2n-bignum/x86_att/p521/bignum_sub_p521.S", + "third_party/s2n-bignum/x86_att/p521/bignum_tolebytes_p521.S", ] diff --git a/aws-lc-sys/builder/cmake_builder.rs b/aws-lc-sys/builder/cmake_builder.rs index b2004a0f5f3..c0d75dd3d02 100644 --- a/aws-lc-sys/builder/cmake_builder.rs +++ b/aws-lc-sys/builder/cmake_builder.rs @@ -2,7 +2,9 @@ // SPDX-License-Identifier: Apache-2.0 OR ISC use crate::OutputLib::{Crypto, RustWrapper, Ssl}; -use crate::{target, target_arch, target_os, target_vendor, test_command, OutputLibType}; +use crate::{ + env_var_to_bool, target, target_arch, target_os, target_vendor, test_command, OutputLibType, +}; use std::env; use std::ffi::OsStr; use std::path::PathBuf; @@ -112,6 +114,16 @@ impl CmakeBuilder { cmake_cfg.define("CMAKE_OSX_ARCHITECTURES", "arm64"); } } + if Some(true) == env_var_to_bool("AWS_LC_SYS_CC_TOML_GENERATOR") { + if target_vendor() == "apple" { + cmake_cfg.define( + "CMAKE_C_FLAGS", + "-ginline-line-tables -grecord-gcc-switches", + ); + } else if target_os() == "linux" { + cmake_cfg.define("CMAKE_C_FLAGS", "-grecord-gcc-switches"); + } + } if cfg!(feature = "asan") { env::set_var("CC", "clang"); diff --git a/scripts/build/generate_build_toml.sh b/scripts/build/generate_build_toml.sh index 165e932ddb4..1b6b7b54ee8 100755 --- a/scripts/build/generate_build_toml.sh +++ b/scripts/build/generate_build_toml.sh @@ -12,51 +12,68 @@ fi SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) PUBLISH=0 REPO_ROOT=$(git rev-parse --show-toplevel) -CRATE_NAME=aws-lc-sys -CRATE_DIR="${REPO_ROOT}/${CRATE_NAME}" -BUILD_CFG_DIR="${CRATE_DIR}/builder/cc" +SYS_CRATE_DIR="${REPO_ROOT}/aws-lc-sys" +BUILD_CFG_DIR="${SYS_CRATE_DIR}/builder/cc" function collect_source_files() { - if [[ "$(uname)" =~ [Dd]arwin ]]; then - dwarfdump --debug-info ${1} | grep DW_AT_decl_file | grep "$(pwd)" | cut -d\" -f 2 | sort | uniq - elif [[ "$(uname)" =~ [Ll]inux ]]; then + OS_NAME=$(uname) + if [[ "${OS_NAME}" =~ [Dd]arwin ]]; then + dwarfdump --debug-info "${1}" | grep DW_AT_name | grep "$(pwd)" | cut -d\" -f 2 | sort | uniq + elif [[ "${OS_NAME}" =~ [Ll]inux ]]; then objdump -g "${1}" | grep DW_AT_name | grep "$(pwd)" | cut -d: -f 4 | sort | uniq else - echo Unknown OS: `uname` + echo Unknown OS: "${OS_NAME}" exit 1 fi } +function find_s2n_bignum_src_dir() { + ARCH_NAME=$(uname -m) + if [[ "${ARCH_NAME}" =~ x86 ]]; then + echo x86_att + else + echo arm + fi +} + function find_generated_src_dir() { - OS_NAME=`uname` - OS_NAME="${OS_NAME,,}" - if [[ ${OS_NAME} == darwin ]]; then + OS_NAME=$(uname) + if [[ "${OS_NAME}" =~ [Dd]arwin ]]; then OS_NAME=mac + elif [[ "${OS_NAME}" =~ [Ll]inux ]]; then + OS_NAME=linux + else + echo Unknown OS: "${OS_NAME}" + exit 1 fi - ARCH_NAME=`uname -m` - ARCH_NAME="${ARCH_NAME,,}" + ARCH_NAME=$(uname -m) echo "${OS_NAME}-${ARCH_NAME}" } function cleanup_source_files() { GS_DIR=$(find_generated_src_dir) - for FILE in ${@}; do - FILE=$(realpath ${FILE}) - # err_data.c is special - echo ${FILE} | sed -e "s/.*\/aws-lc-sys\/aws-lc\///" | sed -e "s/.*\/out\/build\/aws-lc\//generated-src\/${GS_DIR}\//" | sed -e 's/\(.*\)\/[^\/]*\/crypto\/err_data\.c/\1\/err_data.c/' - + S2N_BN_DIR=$(find_s2n_bignum_src_dir) + for FILE in "${@}"; do + if [[ -n "${FILE}" ]]; then + FILE=$(realpath "${FILE}") + echo "${FILE}" | \ + sed -e "s/.*\/aws-lc-sys\/aws-lc\///" | \ + sed -e "s/.*\/out\/build\/aws-lc\/crypto\/fipsmodule\/\(.*\.S\)\.S$/third_party\/s2n-bignum\/${S2N_BN_DIR}\/\1/" | \ + sed -e "s/.*\/out\/build\/aws-lc\//generated-src\/${GS_DIR}\//" | \ + sed -e 's/\(.*\)\/[^\/]*\/crypto\/err_data\.c/\1\/err_data.c/' + fi done } function process_source_files() { - cleanup_source_files ${@} | sort | uniq + cleanup_source_files "${@}" | sort | uniq } function verify_source_files() { - for FILE in ${@}; do - FILE_PATH="${CRATE_DIR}/aws-lc/${FILE}" + for FILE in "${@}"; do + FILE_PATH="${SYS_CRATE_DIR}/aws-lc/${FILE}" if [[ ! -f "${FILE_PATH}" ]]; then - echo File does not exist: ${FILE_PATH} + echo File does not exist: "${FILE_PATH}" exit 1 fi done @@ -74,7 +91,7 @@ name = "crypto" flags = [] sources = [ EOF - for FILE in ${@}; do + for FILE in "${@}"; do echo " \"${FILE}\"," done echo "]" @@ -84,25 +101,28 @@ EOF pushd "${REPO_ROOT}" cargo clean -AWS_LC_SYS_CMAKE_BUILDER=1 cargo build --package ${CRATE_NAME} --profile dev +AWS_LC_SYS_CMAKE_BUILDER=1 AWS_LC_SYS_CC_TOML_GENERATOR=1 cargo build --package aws-lc-sys --profile dev -LIB_CRYPTO_PATH=$(find target/debug -name "libaws_lc_0_*crypto.a") +LIB_CRYPTO_PATH=$(find target/debug -name "libaws_lc_0_*crypto.a"| head -n 1) LIB_CRYPTO_PATH="${REPO_ROOT}/${LIB_CRYPTO_PATH}" -SOURCE_FILES=$(collect_source_files ${LIB_CRYPTO_PATH}) -PROCESSED_SRC_FILES=$(process_source_files ${SOURCE_FILES}) -verify_source_files ${PROCESSED_SRC_FILES} +SOURCE_FILES=($(collect_source_files "${LIB_CRYPTO_PATH}")) +PROCESSED_SRC_FILES=($(process_source_files "${SOURCE_FILES[@]}")) -RUST_TRIPLE=$(rustc -vV | grep host | sed -e 's/host:\W*\(\S*\)/\1/') -BUILD_CFG_PATH="${BUILD_CFG_DIR}"/${RUST_TRIPLE}.toml +verify_source_files "${PROCESSED_SRC_FILES[@]}" -generate_toml ${PROCESSED_SRC_FILES} > ${BUILD_CFG_PATH} +RUST_TRIPLE=$(rustc -vV | grep host | sed -e 's/host: *\(\w*\)/\1/') +BUILD_CFG_PATH="${BUILD_CFG_DIR}/${RUST_TRIPLE}.toml" + +generate_toml ${PROCESSED_SRC_FILES[@]} > ${BUILD_CFG_PATH} echo echo Build configuration written to: ${BUILD_CFG_PATH} echo -AWS_LC_SYS_CMAKE_BUILDER=0 cargo build --package ${CRATE_NAME} --profile dev +cargo clean +AWS_LC_SYS_CMAKE_BUILDER=0 cargo build --package aws-lc-sys --profile dev +AWS_LC_SYS_CMAKE_BUILDER=0 cargo test --package aws-lc-rs --profile dev popd