Skip to content

Commit

Permalink
make rust features disable instead of enable and use in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Aug 21, 2024
1 parent 6c25fc1 commit 1158b04
Show file tree
Hide file tree
Showing 38 changed files with 159 additions and 140 deletions.
27 changes: 13 additions & 14 deletions docs/docs/icicle/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ You can customize your ICICLE build with the following flags:

#### Features

By default, all [features](./libraries.md#supported-curves-and-operations) are enabled.

:::note
Installed backends may implement and register all APIs, therefore by default we include them in the frontend part too.
:::
By default, all [features](./libraries.md#supported-curves-and-operations) are enabled.
This is since installed backends may implement and register all APIs. Missing APIs in the frontend would cause linkage to fail due to missing symbols. Therefore by default we include them in the frontend part too.

To disable features, add the following to the cmake command.
- ntt: `-DNTT=OFF`
Expand All @@ -103,6 +100,10 @@ To disable features, add the following to the cmake command.
- ecntt: `-DECNTT=OFF`
- extension field: `-DEXT_FIELD=OFF`

:::tip
Disabling features is useful when developing with a backend that is slow to compile (e.g. CUDA backend);
:::

### Rust: Build, Test, and Install

To build and test ICICLE in Rust, follow these steps:
Expand All @@ -116,19 +117,17 @@ cd wrappers/rust # or go to a specific field/curve 'cd wrappers/rust/icicle-fiel
```bash
cargo build --release
```
By default, all [features](./libraries.md#supported-curves-and-operations) are enabled.
In rust we have the following features:
- `g2` for G2 MSM
- `ec_ntt` for ECNTT
By default, all [supported features](./libraries.md#supported-curves-and-operations) are enabled. [See here for more details.](#features)
To disable, use the following cargo features:
- `no_g2` to disable G2 MSM
- `no_ecntt` to disable ECNTT

They can be disabled by
They can be disabled as follows:
```bash
cargo build --release --no-default-features # disable all features
cargo build --release --no-default-features --features "ec_ntt" # disable all except ec_ntt
cargo build --release --no-default-features --features "g2" # disable all except g2
cargo build --release --no-default-features --features=no_ecntt,no_g2
```

:::tip
:::note
If you have access to cuda backend repo, it can be built along ICICLE frontend by using the following cargo features:
- `cuda_backend` : if the cuda backend resides in `icicle/backend/cuda`
- `pull_cuda_backend` : to pull main branch and build it
Expand Down
4 changes: 2 additions & 2 deletions examples/c++/best-practice-ntt/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -S "${ICILE_DIR}" -B build/icicle
fi
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build/example

Expand Down
4 changes: 2 additions & 2 deletions examples/c++/msm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DG2=ON -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DG2=ON -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -S "${ICILE_DIR}" -B build/icicle
fi
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build/example

Expand Down
4 changes: 2 additions & 2 deletions examples/c++/ntt/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -S "${ICILE_DIR}" -B build/icicle
fi
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build/example

Expand Down
2 changes: 1 addition & 1 deletion examples/c++/pedersen-commitment/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
Expand Down
2 changes: 1 addition & 1 deletion examples/c++/polynomial-api/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void example_device_memory_view()
auto coset_evals = std::make_unique<scalar_t[]>(size);
auto ntt_config = default_ntt_config<scalar_t>();
ntt_config.are_inputs_on_device = true; // using the device data directly as a view
ntt_config.coset_gen = get_root_of_unity<scalar_t>(size * 2);
ICICLE_CHECK(get_root_of_unity<scalar_t>(size * 2, &ntt_config.coset_gen));
ntt(d_coeffs.get(), size, NTTDir::kForward, ntt_config, coset_evals.get());
}

Expand Down
2 changes: 1 addition & 1 deletion examples/c++/polynomial-api/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
Expand Down
4 changes: 2 additions & 2 deletions examples/c++/polynomial_multiplication/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -DMSM=OFF -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DCURVE=bn254 -S "${ICILE_DIR}" -B build/icicle
fi
cmake -DCMAKE_BUILD_TYPE=Release -S . -B build/example

Expand Down
2 changes: 1 addition & 1 deletion examples/c++/risc0/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cmake -DCMAKE_BUILD_TYPE=Release -DFIELD=babybear -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
cmake -DCMAKE_BUILD_TYPE=Release -DFIELD=babybear -DMSM=OFF -DG2=OFF -DECNTT=OFF -DCUDA_BACKEND=local -S "${ICILE_DIR}" -B build/icicle
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "build/icicle/backend")
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
Expand Down
9 changes: 7 additions & 2 deletions examples/rust/msm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ edition = "2018"
[dependencies]
icicle-runtime = { path = "../../../wrappers/rust_v3/icicle-runtime" }
icicle-core = { path = "../../../wrappers/rust_v3/icicle-core" }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254", features = ["g2"] }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254" }
icicle-bls12-377 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bls12-377" }
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend", "icicle-bn254/cuda_backend", "icicle-bls12-377/cuda_backend"]
cuda = ["icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bls12-377/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/no_ecntt"
]
11 changes: 9 additions & 2 deletions examples/rust/ntt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ edition = "2018"
[dependencies]
icicle-runtime = { path = "../../../wrappers/rust_v3/icicle-runtime" }
icicle-core = { path = "../../../wrappers/rust_v3/icicle-core" }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254", features = ["g2"] }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254" }
icicle-bls12-377 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bls12-377" }

clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend", "icicle-bn254/cuda_backend", "icicle-bls12-377/cuda_backend"]
cuda = ["icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-bls12-377/cuda_backend",
"icicle-bls12-377/no_ecntt",
"icicle-bls12-377/no_g2"
]
9 changes: 7 additions & 2 deletions examples/rust/polynomials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ edition = "2018"
[dependencies]
icicle-runtime = { path = "../../../wrappers/rust_v3/icicle-runtime" }
icicle-core = { path = "../../../wrappers/rust_v3/icicle-core" }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254", features = ["g2"] }
icicle-bn254 = { path = "../../../wrappers/rust_v3/icicle-curves/icicle-bn254" }
icicle-babybear = { path = "../../../wrappers/rust_v3/icicle-fields/icicle-babybear" }

clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend", "icicle-bn254/cuda_backend", "icicle-babybear/cuda_backend"]
cuda = ["icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-babybear/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
]

4 changes: 2 additions & 2 deletions examples/rust/polynomials/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ ICICLE_CUDA_SOURCE_DIR="${ICILE_DIR}/backend/cuda"
# Build Icicle and the example app that links to it
if [ "$DEVICE_TYPE" == "CUDA" ] && [ ! -d "${ICICLE_BACKEND_INSTALL_DIR}" ] && [ -d "${ICICLE_CUDA_SOURCE_DIR}" ]; then
echo "Building icicle with CUDA backend"
cargo build --release --features=cuda
cargo build --release --no-default-features --features=cuda
export ICICLE_BACKEND_INSTALL_DIR=$(realpath "./target/release/deps/icicle/lib/backend")
cargo run --release --features=cuda -- --device-type "${DEVICE_TYPE}"
cargo run --release --no-default-features --features=cuda -- --device-type "${DEVICE_TYPE}"
else
echo "Building icicle without CUDA backend, ICICLE_BACKEND_INSTALL_DIR=${ICICLE_BACKEND_INSTALL_DIR}"
export ICICLE_BACKEND_INSTALL_DIR="$ICICLE_BACKEND_INSTALL_DIR";
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/cmake/curve.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function(check_curve CURVE CURVE_INDEX_OUT FEATURES_STRING_OUT)

if (CURVE STREQUAL CURVE_NAME)
set(IS_CURVE_SUPPORTED TRUE)
message(STATUS "building CURVE_NAME=${CURVE_NAME} ; CURVE_INDEX=${CURVE_INDEX} ; FEATURES=${FEATURES_STRING}")
message(STATUS "building CURVE_NAME=${CURVE_NAME} ; CURVE_INDEX=${CURVE_INDEX} ; SUPPORTED_FEATURES=${FEATURES_STRING}")
# Output the CURVE_INDEX and FEATURES_STRING
set(${CURVE_INDEX_OUT} "${CURVE_INDEX}" PARENT_SCOPE)
set(${FEATURES_STRING_OUT} "${FEATURES_STRING}" PARENT_SCOPE)
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/cmake/field.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function(check_field FIELD FIELD_INDEX_OUT FEATURES_STRING_OUT)

if (FIELD STREQUAL FIELD_NAME)
set(IS_FIELD_SUPPORTED TRUE)
message(STATUS "building FIELD_NAME=${FIELD_NAME} ; FIELD_INDEX=${FIELD_INDEX} ; FEATURES=${FEATURES_STRING}")
message(STATUS "building FIELD_NAME=${FIELD_NAME} ; FIELD_INDEX=${FIELD_INDEX} ; SUPPORTED_FEATURES=${FEATURES_STRING}")
# Output the FIELD_INDEX and FEATURES_STRING
set(${FIELD_INDEX_OUT} "${FIELD_INDEX}" PARENT_SCOPE)
set(${FEATURES_STRING_OUT} "${FEATURES_STRING}" PARENT_SCOPE)
Expand Down
11 changes: 5 additions & 6 deletions icicle_v3/cmake/target_editor.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ endfunction()

function(handle_ntt TARGET FEATURE_LIST)
if(NTT AND "NTT" IN_LIST FEATURE_LIST)
target_compile_definitions(${TARGET} PUBLIC NTT=${NTT})
target_compile_definitions(${TARGET} PUBLIC NTT=${NTT})
target_sources(${TARGET} PRIVATE
src/ntt.cpp
src/polynomials/polynomials.cpp
src/polynomials/polynomials_c_api.cpp
src/polynomials/polynomials_abstract_factory.cpp
)
set(NTT ON CACHE BOOL "Enable NTT feature" FORCE)
else()
set(NTT OFF CACHE BOOL "NTT not available for this field" FORCE)
message(STATUS "NTT not available for this field")
endif()
set(NTT ON CACHE BOOL "Enable NTT feature" FORCE)
else()
set(NTT OFF CACHE BOOL "NTT not available for this field" FORCE)
endif()
endfunction()

function(handle_ext_field TARGET FEATURE_LIST)
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ extern "C" eIcicleError icicle_load_backend(const char* path, bool is_recursive)

auto load_library = [](const char* filePath) {
ICICLE_LOG_DEBUG << "Attempting load: " << filePath;
void* handle = dlopen(filePath, RTLD_LAZY | RTLD_GLOBAL);
void* handle = dlopen(filePath, RTLD_LAZY);
if (!handle) { ICICLE_LOG_ERROR << "Failed to load " << filePath << ": " << dlerror(); }
};

Expand Down
4 changes: 2 additions & 2 deletions wrappers/rust_v3/icicle-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ serial_test = "3.0.0"
once_cell = "1.10.0"

[features]
g2 = []
ec_ntt = []
no_g2 = []
no_ecntt = []
7 changes: 3 additions & 4 deletions wrappers/rust_v3/icicle-curves/icicle-bls12-377/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ serial_test = "3.0.0"
cmake = "0.1.50"

[features]
default = ["g2", "ec_ntt"]
default = []
bw6-761 = []
bw6-761-g2 = ["bw6-761"]
g2 = ["icicle-core/g2"]
ec_ntt = ["icicle-core/ec_ntt"]
no_g2 = ["icicle-core/no_g2"]
no_ecntt = ["icicle-core/no_ecntt"]
cuda_backend = ["icicle-runtime/cuda_backend"]
pull_cuda_backend = ["icicle-runtime/pull_cuda_backend"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "ec_ntt")]
#[cfg(not(feature = "no_ecntt"))]
use icicle_bls12_377::curve::{CurveCfg, ScalarField};

#[cfg(feature = "ec_ntt")]
#[cfg(not(feature = "no_ecntt"))]
use icicle_core::impl_ecntt_bench;
#[cfg(feature = "ec_ntt")]
#[cfg(not(feature = "no_ecntt"))]
impl_ecntt_bench!("bls12_377", ScalarField, CurveCfg);

#[cfg(not(feature = "ec_ntt"))]
Expand Down
44 changes: 24 additions & 20 deletions wrappers/rust_v3/icicle-curves/icicle-bls12-377/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ fn main() {
.define("CMAKE_BUILD_TYPE", "Release")
.define("CMAKE_INSTALL_PREFIX", &icicle_install_dir);

#[cfg(feature = "cuda_backend")]
config.define("CUDA_BACKEND", "local");

#[cfg(feature = "pull_cuda_backend")]
config.define("CUDA_BACKEND", "main");

// build (or pull and build) cuda backend if feature enabled.
// Note: this requires access to the repo
if cfg!(feature = "cuda_backend") {
config.define("CUDA_BACKEND", "local");
} else if cfg!(feature = "pull_cuda_backend") {
config.define("CUDA_BACKEND", "main");
}
// Optional Features that are default ON (so that default matches any backend)
if !cfg!(feature = "g2") {
if cfg!(feature = "no_g2") {
config.define("G2", "OFF");
}
if !cfg!(feature = "ec_ntt") {
if cfg!(feature = "no_ecntt") {
config.define("ECNTT", "OFF");
}

Expand All @@ -61,18 +62,21 @@ fn main() {
.define("CMAKE_BUILD_TYPE", "Release")
.define("CMAKE_INSTALL_PREFIX", &icicle_install_dir);

#[cfg(feature = "cuda_backend")]
config_bw.define("CUDA_BACKEND", "local");

#[cfg(feature = "pull_cuda_backend")]
config_bw.define("CUDA_BACKEND", "main");

// Optional Features
#[cfg(feature = "bw6-761-g2")]
config_bw.define("G2", "ON");

#[cfg(feature = "ec_ntt")]
config_bw.define("ECNTT", "OFF");
// build (or pull and build) cuda backend if feature enabled.
// Note: this requires access to the repo
if cfg!(feature = "cuda_backend") {
config.define("CUDA_BACKEND", "local");
} else if cfg!(feature = "pull_cuda_backend") {
config.define("CUDA_BACKEND", "main");
}

// Optional Features that are default ON (so that default matches any backend)
if cfg!(feature = "no_g2") {
config.define("G2", "OFF");
}
if cfg!(feature = "no_ecntt") {
config.define("ECNTT", "OFF");
}

// Build
let _ = config_bw
Expand Down
10 changes: 5 additions & 5 deletions wrappers/rust_v3/icicle-curves/icicle-bls12-377/src/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use icicle_runtime::{

pub(crate) const SCALAR_LIMBS: usize = 8;
pub(crate) const BASE_LIMBS: usize = 12;
#[cfg(feature = "g2")]
#[cfg(not(feature = "no_g2"))]
pub(crate) const G2_BASE_LIMBS: usize = 24;

impl_scalar_field!("bls12_377", bls12_377_sf, SCALAR_LIMBS, ScalarField, ScalarCfg);
Expand All @@ -34,9 +34,9 @@ impl_curve!(
G1Projective
);

#[cfg(feature = "g2")]
#[cfg(not(feature = "no_g2"))]
impl_field!(G2_BASE_LIMBS, G2BaseField, G2BaseCfg);
#[cfg(feature = "g2")]
#[cfg(not(feature = "no_g2"))]
impl_curve!(
"bls12_377_g2",
bls12_377_g2,
Expand All @@ -50,7 +50,7 @@ impl_curve!(
#[cfg(test)]
mod tests {
use super::{CurveCfg, ScalarField, BASE_LIMBS};
#[cfg(feature = "g2")]
#[cfg(not(feature = "no_g2"))]
use super::{G2CurveCfg, G2_BASE_LIMBS};
use icicle_core::curve::Curve;
use icicle_core::test_utilities;
Expand All @@ -60,7 +60,7 @@ mod tests {

impl_field_tests!(ScalarField);
impl_curve_tests!(BASE_LIMBS, CurveCfg);
#[cfg(feature = "g2")]
#[cfg(not(feature = "no_g2"))]
mod g2 {
use super::*;
impl_curve_tests!(G2_BASE_LIMBS, G2CurveCfg);
Expand Down
Loading

0 comments on commit 1158b04

Please sign in to comment.