From dc3ae8207ebcd07dc882909f159a7cadc5f74f11 Mon Sep 17 00:00:00 2001 From: Hasan Mahmood Date: Wed, 4 Dec 2024 16:15:27 +0200 Subject: [PATCH 1/2] Add support to add features during cargo build --- rust_build_utils/rust_utils.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rust_build_utils/rust_utils.py b/rust_build_utils/rust_utils.py index db7fc39..a0969fd 100644 --- a/rust_build_utils/rust_utils.py +++ b/rust_build_utils/rust_utils.py @@ -4,7 +4,7 @@ import shutil import importlib from typing import Any, Dict, List, Optional, Tuple -from dataclasses import dataclass +from dataclasses import dataclass, field from rust_build_utils.rust_utils_config import GLOBAL_CONFIG from pathlib import Path from rust_build_utils.msvc import activate_msvc, deactivate_msvc, is_msvc_active @@ -26,6 +26,7 @@ class CargoConfig: arch: str debug: bool rust_target: str = "" + features: list = field(default_factory=list) def __post_init__(self): if self.arch == "arm64": @@ -38,6 +39,9 @@ def __post_init__(self): def is_msvc(self): return self.rust_target.endswith("-msvc") + def add_feature(self, features: List[str]): + self.features = features + @dataclass class Project: @@ -324,6 +328,12 @@ def _build_packages( for p in packages: args.append("--package") args.append(p) + + if config.features: + args.append("--features") + for f in config.features: + args.append(f) + args.extend(extra_args or []) run_command(args) From 7f78001fbc3b151bbcfa6d1c43d92cbd3f8e04fa Mon Sep 17 00:00:00 2001 From: Hasan Mahmood Date: Wed, 4 Dec 2024 17:58:59 +0200 Subject: [PATCH 2/2] Modify function name to features --- rust_build_utils/rust_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust_build_utils/rust_utils.py b/rust_build_utils/rust_utils.py index a0969fd..639101d 100644 --- a/rust_build_utils/rust_utils.py +++ b/rust_build_utils/rust_utils.py @@ -39,7 +39,7 @@ def __post_init__(self): def is_msvc(self): return self.rust_target.endswith("-msvc") - def add_feature(self, features: List[str]): + def add_features(self, features: List[str]): self.features = features