From e91cc685b1f87ca9661833f10b1d0822f3678ebf Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Thu, 29 Nov 2018 10:58:05 -0800 Subject: [PATCH] Don't generate unused constants in build.rs. --- build.rs | 58 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/build.rs b/build.rs index f24e47b..e9c2a66 100644 --- a/build.rs +++ b/build.rs @@ -44,33 +44,31 @@ mod macros; // Public modules -#[path = "src/scalar.rs"] -mod scalar; -#[path = "src/montgomery.rs"] -mod montgomery; -#[path = "src/edwards.rs"] -mod edwards; -#[path = "src/ristretto.rs"] -mod ristretto; #[path = "src/constants.rs"] mod constants; +#[path = "src/edwards.rs"] +mod edwards; +#[path = "src/montgomery.rs"] +mod montgomery; +#[path = "src/ristretto.rs"] +mod ristretto; +#[path = "src/scalar.rs"] +mod scalar; #[path = "src/traits.rs"] mod traits; // Internal modules -#[path = "src/field.rs"] -mod field; #[path = "src/backend/mod.rs"] mod backend; +#[path = "src/field.rs"] +mod field; #[path = "src/prelude.rs"] mod prelude; #[path = "src/window.rs"] mod window; use edwards::EdwardsBasepointTable; -use backend::serial::curve_models::AffineNielsPoint; -use window::NafLookupTable8; fn main() { // Enable the "stage2_build" feature in the main build stage @@ -97,7 +95,6 @@ use edwards::EdwardsBasepointTable; use backend::serial::curve_models::AffineNielsPoint; use window::LookupTable; -use window::NafLookupTable8; /// Table containing precomputed multiples of the Ed25519 basepoint \\\\(B = (x, 4/5)\\\\). pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN; @@ -107,20 +104,35 @@ pub const ED25519_BASEPOINT_TABLE: EdwardsBasepointTable = ED25519_BASEPOINT_TAB pub const ED25519_BASEPOINT_TABLE_INNER_DOC_HIDDEN: EdwardsBasepointTable = {:?}; \n\n", &table - ).as_bytes(), - ).unwrap(); + ) + .as_bytes(), + ) + .unwrap(); // Now generate AFFINE_ODD_MULTIPLES_OF_BASEPOINT - let B = &constants::ED25519_BASEPOINT_POINT; - let odd_multiples = NafLookupTable8::::from(B); + // if we are going to build the serial scalar_mul backend + #[cfg(not(all( + feature = "simd_backend", + any(target_feature = "avx2", target_feature = "avx512ifma") + )))] + { + use backend::serial::curve_models::AffineNielsPoint; + use window::NafLookupTable8; - f.write_all( - format!( - "\n + let B = &constants::ED25519_BASEPOINT_POINT; + let odd_multiples = NafLookupTable8::::from(B); + + f.write_all( + format!( + "\n +use window::NafLookupTable8; /// Odd multiples of the basepoint `[B, 3B, 5B, 7B, 9B, 11B, 13B, 15B, ..., 127B]`. pub(crate) const AFFINE_ODD_MULTIPLES_OF_BASEPOINT: NafLookupTable8 = {:?}; \n\n", - &odd_multiples - ).as_bytes(), - ).unwrap(); + &odd_multiples + ) + .as_bytes(), + ) + .unwrap(); + } }