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] aws-lc-sys: avoid building unnecessary source files #711

Draft
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion aws-lc-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fips = ["dep:aws-lc-fips-sys"]

[dependencies]
untrusted = { version = "0.7.1", optional = true }
aws-lc-sys = { version = "0.26.0", path = "../aws-lc-sys", optional = true }
aws-lc-sys = { version = "0.26.0", path = "../aws-lc-sys", optional = true, features = ["aws-lc-rs"] }
aws-lc-fips-sys = { version = "0.13.1", path = "../aws-lc-fips-sys", optional = true }
zeroize = "1.7"
paste = "1.0.11"
Expand Down
1 change: 1 addition & 0 deletions aws-lc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ asan = []
ssl = ['bindgen']
bindgen = ["dep:bindgen"] # Generate the bindings on the targetted platform as a fallback mechanism.
prebuilt-nasm = []
aws-lc-rs = []

[build-dependencies]
cmake = "0.1.48"
Expand Down
196 changes: 195 additions & 1 deletion aws-lc-sys/builder/cc_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,194 @@ use crate::{
};
use std::path::PathBuf;

const AWS_LC_RS_UNNEEDED_SRC: [&str; 177] = [
"crypto/asn1/a_bitstr.c",
"crypto/asn1/a_bool.c",
"crypto/asn1/a_d2i_fp.c",
"crypto/asn1/a_dup.c",
"crypto/asn1/a_gentm.c",
"crypto/asn1/a_i2d_fp.c",
"crypto/asn1/a_int.c",
"crypto/asn1/a_mbstr.c",
"crypto/asn1/a_object.c",
"crypto/asn1/a_octet.c",
"crypto/asn1/a_strex.c",
"crypto/asn1/a_strnid.c",
"crypto/asn1/a_time.c",
"crypto/asn1/a_type.c",
"crypto/asn1/a_utctm.c",
"crypto/asn1/a_utf8.c",
"crypto/asn1/asn1_lib.c",
"crypto/asn1/asn1_par.c",
"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/base64/base64.c",
"crypto/bio/bio.c",
"crypto/bio/bio_mem.c",
"crypto/bio/connect.c",
"crypto/bio/errno.c",
"crypto/bio/fd.c",
"crypto/bio/file.c",
"crypto/bio/hexdump.c",
"crypto/bio/pair.c",
"crypto/bio/printf.c",
"crypto/bio/socket.c",
"crypto/bio/socket_helper.c",
"crypto/blake2/blake2.c",
"crypto/buf/buf.c",
"crypto/bytestring/ber.c",
"crypto/bytestring/unicode.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_des.c",
"crypto/cipher_extra/e_null.c",
"crypto/cipher_extra/e_rc2.c",
"crypto/cipher_extra/e_rc4.c",
"crypto/cipher_extra/e_tls.c",
"crypto/cipher_extra/tls_cbc.c",
"crypto/conf/conf.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/dh/dh_decrepit.c",
"crypto/decrepit/evp/evp_do_all.c",
"crypto/decrepit/obj/obj_decrepit.c",
"crypto/decrepit/rsa/rsa_decrepit.c",
"crypto/decrepit/x509/x509_decrepit.c",
"crypto/des/des.c",
"crypto/ec_extra/ec_derive.c",
"crypto/ec_extra/hash_to_curve.c",
"crypto/ecdh_extra/ecdh_extra.c",
"crypto/evp_extra/print.c",
"crypto/evp_extra/scrypt.c",
"crypto/evp_extra/sign.c",
"crypto/hpke/hpke.c",
"crypto/hrss/hrss.c",
"crypto/obj/obj_xref.c",
"crypto/ocsp/ocsp_asn.c",
"crypto/ocsp/ocsp_client.c",
"crypto/ocsp/ocsp_extension.c",
"crypto/ocsp/ocsp_http.c",
"crypto/ocsp/ocsp_lib.c",
"crypto/ocsp/ocsp_print.c",
"crypto/ocsp/ocsp_server.c",
"crypto/ocsp/ocsp_verify.c",
"crypto/pem/pem_all.c",
"crypto/pem/pem_info.c",
"crypto/pem/pem_lib.c",
"crypto/pem/pem_oth.c",
"crypto/pem/pem_pk8.c",
"crypto/pem/pem_pkey.c",
"crypto/pem/pem_x509.c",
"crypto/pem/pem_xaux.c",
"crypto/pkcs7/bio/cipher.c",
"crypto/pkcs7/bio/md.c",
"crypto/pkcs7/pkcs7.c",
"crypto/pkcs7/pkcs7_asn1.c",
"crypto/pkcs7/pkcs7_x509.c",
"crypto/pkcs8/p5_pbev2.c",
"crypto/pkcs8/pkcs8.c",
"crypto/pkcs8/pkcs8_x509.c",
"crypto/pool/pool.c",
"crypto/rc4/rc4.c",
"crypto/rsa_extra/rsa_print.c",
"crypto/siphash/siphash.c",
"crypto/spake25519/spake25519.c",
"crypto/trust_token/pmbtoken.c",
"crypto/trust_token/trust_token.c",
"crypto/trust_token/voprf.c",
"crypto/x509/a_digest.c",
"crypto/x509/a_sign.c",
"crypto/x509/a_verify.c",
"crypto/x509/algorithm.c",
"crypto/x509/asn1_gen.c",
"crypto/x509/by_dir.c",
"crypto/x509/by_file.c",
"crypto/x509/i2d_pr.c",
"crypto/x509/name_print.c",
"crypto/x509/policy.c",
"crypto/x509/rsa_pss.c",
"crypto/x509/t_crl.c",
"crypto/x509/t_req.c",
"crypto/x509/t_x509.c",
"crypto/x509/t_x509a.c",
"crypto/x509/v3_akey.c",
"crypto/x509/v3_akeya.c",
"crypto/x509/v3_alt.c",
"crypto/x509/v3_bcons.c",
"crypto/x509/v3_bitst.c",
"crypto/x509/v3_conf.c",
"crypto/x509/v3_cpols.c",
"crypto/x509/v3_crld.c",
"crypto/x509/v3_enum.c",
"crypto/x509/v3_extku.c",
"crypto/x509/v3_genn.c",
"crypto/x509/v3_ia5.c",
"crypto/x509/v3_info.c",
"crypto/x509/v3_int.c",
"crypto/x509/v3_lib.c",
"crypto/x509/v3_ncons.c",
"crypto/x509/v3_ocsp.c",
"crypto/x509/v3_pcons.c",
"crypto/x509/v3_pmaps.c",
"crypto/x509/v3_prn.c",
"crypto/x509/v3_purp.c",
"crypto/x509/v3_skey.c",
"crypto/x509/v3_utl.c",
"crypto/x509/x509.c",
"crypto/x509/x509_att.c",
"crypto/x509/x509_cmp.c",
"crypto/x509/x509_d2.c",
"crypto/x509/x509_def.c",
"crypto/x509/x509_ext.c",
"crypto/x509/x509_lu.c",
"crypto/x509/x509_obj.c",
"crypto/x509/x509_req.c",
"crypto/x509/x509_set.c",
"crypto/x509/x509_trs.c",
"crypto/x509/x509_txt.c",
"crypto/x509/x509_v3.c",
"crypto/x509/x509_vfy.c",
"crypto/x509/x509_vpm.c",
"crypto/x509/x509cset.c",
"crypto/x509/x509name.c",
"crypto/x509/x509rset.c",
"crypto/x509/x509spki.c",
"crypto/x509/x_algor.c",
"crypto/x509/x_all.c",
"crypto/x509/x_attrib.c",
"crypto/x509/x_crl.c",
"crypto/x509/x_exten.c",
"crypto/x509/x_name.c",
"crypto/x509/x_pubkey.c",
"crypto/x509/x_req.c",
"crypto/x509/x_sig.c",
"crypto/x509/x_spki.c",
"crypto/x509/x_val.c",
"crypto/x509/x_x509.c",
"crypto/x509/x_x509a.c",
];

pub(crate) struct CcBuilder {
manifest_dir: PathBuf,
out_dir: PathBuf,
build_prefix: Option<String>,
output_lib_type: OutputLibType,
}

use std::collections::HashSet;
use std::{env, fs};

pub(crate) struct Library {
Expand Down Expand Up @@ -223,8 +404,21 @@ impl CcBuilder {
fn add_all_files(&self, lib: &Library, cc_build: &mut cc::Build) {
use core::str::FromStr;
cc_build.file(PathBuf::from_str("rust_wrapper.c").unwrap());

let aws_lc_rs_unneeded_files = HashSet::from(AWS_LC_RS_UNNEEDED_SRC);
let feature_aws_lc_rs = cfg!(feature = "aws-lc-rs");
if feature_aws_lc_rs {
emit_warning(
format!(
"Feature aws-lc-rs enabled. Ignoring source file: {:?}",
AWS_LC_RS_UNNEEDED_SRC
)
.as_str(),
);
}
for source in lib.sources {
if feature_aws_lc_rs && aws_lc_rs_unneeded_files.contains(source) {
continue;
}
let source_path = self.manifest_dir.join("aws-lc").join(source);
let is_asm = std::path::Path::new(source)
.extension()
Expand Down
Loading