This is an automated email from the ASF dual-hosted git repository.

martinzink pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git


The following commit(s) were added to refs/heads/main by this push:
     new 92683f648 MINIFICPP-2938 Add rust build dependencies to bootstrap 
script (#2307)
92683f648 is described below

commit 92683f6482898d1e3c0862a1d35f64d9cb9af240
Author: Gabor Gyimesi <[email protected]>
AuthorDate: Mon Nov 30 14:10:34 2026 +0100

    MINIFICPP-2938 Add rust build dependencies to bootstrap script (#2307)
---
 README.md                      |  12 +++++
 bootstrap/cli.py               |  16 ++++--
 bootstrap/package_manager.py   | 116 ++++++++++++++++++++++++++++++++---------
 bootstrap/system_dependency.py |   2 +
 4 files changed, 118 insertions(+), 28 deletions(-)

diff --git a/README.md b/README.md
index a06ba3e0e..7a51a3cc9 100644
--- a/README.md
+++ b/README.md
@@ -154,6 +154,18 @@ and rebuild.
 
 **NOTE:** On Windows if Strawberry Perl is used the 
`${StrawberryPerlRoot}\c\bin` directory should not be part of the PATH 
environment variable as the patch executable in this directory interferes with 
git's patch executable. Alternatively [scoop](https://scoop.sh/) package 
manager can also be used to install Strawberry Perl using the command `scoop 
install perl` that does not pollute the PATH variable. Also on Windows CMake's 
CPack is used for MSI generation, building WIX files and call [...]
 
+#### Rust Extensions
+
+The following are only required when building with `-DMINIFI_RUST=ON` (e.g. 
for the PGP and Tensor extensions):
+
+* Rust toolchain 1.95 or greater, including `cargo` and `rustc` -- it is 
recommended to install it using [rustup](https://rustup.rs/)
+* libclang -- required by [bindgen](https://github.com/rust-lang/rust-bindgen) 
to generate the Rust bindings of the MiNiFi C API
+  * Linux: the libclang development package, e.g. `apt install libclang-dev 
clang` on Aptitude based distributions or `dnf install clang clang-devel` on 
rpm-based distributions
+  * macOS: `brew install llvm`
+  * Windows: LLVM, e.g. `choco install llvm`, or the "C++ Clang tools for 
Windows" component of Visual Studio
+
+The [bootstrap scripts](#bootstrapping) install the Rust toolchain and 
libclang automatically when the `MINIFI_RUST` option is enabled.
+
 #### Bundled Thirdparty Dependencies
 
 The [NOTICE](NOTICE) file lists all the bundled thirdparty dependencies that 
are built and linked statically to MiNiFi or one of its extensions. The 
licenses of these projects can be found in the [LICENSE](LICENSE) file.
diff --git a/bootstrap/cli.py b/bootstrap/cli.py
index 62ddef1f9..e0358f9cc 100644
--- a/bootstrap/cli.py
+++ b/bootstrap/cli.py
@@ -143,11 +143,18 @@ def _conan_build_env_prefix(minifi_options: 
MinifiOptions) -> str:
     return ""
 
 
+def _cargo_path_prefix() -> str:
+    if platform.system() == "Windows":
+        return ""
+    cargo_bin = os.path.expanduser("~/.cargo/bin")
+    return f'export PATH="{cargo_bin}:$PATH" && '
+
+
 def run_cmake(minifi_options: MinifiOptions, package_manager: PackageManager):
     if not os.path.exists(minifi_options.build_dir):
         os.mkdir(minifi_options.build_dir)
     cmake_cmd = (
-        f"{_conan_build_env_prefix(minifi_options)}cmake 
{minifi_options.create_cmake_generator_str()} 
{minifi_options.create_cmake_use_conan_str()} "
+        f"{_cargo_path_prefix()}{_conan_build_env_prefix(minifi_options)}cmake 
{minifi_options.create_cmake_generator_str()} 
{minifi_options.create_cmake_use_conan_str()} "
         f'{minifi_options.create_cmake_options_str()} 
"{minifi_options.source_dir}" -B "{minifi_options.build_dir}"'
     )
     res = package_manager.run_cmd(cmake_cmd)
@@ -156,14 +163,17 @@ def run_cmake(minifi_options: MinifiOptions, 
package_manager: PackageManager):
 
 
 def do_build(minifi_options: MinifiOptions, package_manager: PackageManager):
-    build_cmd = f'{_conan_build_env_prefix(minifi_options)}cmake --build 
"{minifi_options.build_dir!s}" {minifi_options.create_cmake_build_flags_str()}'
+    build_cmd = (
+        f"{_cargo_path_prefix()}{_conan_build_env_prefix(minifi_options)}"
+        f'cmake --build "{minifi_options.build_dir!s}" 
{minifi_options.create_cmake_build_flags_str()}'
+    )
     res = package_manager.run_cmd(build_cmd)
     print("Build was successful" if res else "Build was unsuccessful")
     return res
 
 
 def do_package(minifi_options: MinifiOptions, package_manager: PackageManager):
-    build_cmd = f'{_conan_build_env_prefix(minifi_options)}cmake --build 
"{minifi_options.build_dir!s}" --target package 
{minifi_options.create_cmake_build_flags_str()}'
+    build_cmd = 
f'{_cargo_path_prefix()}{_conan_build_env_prefix(minifi_options)}cmake --build 
"{minifi_options.build_dir!s}" --target package 
{minifi_options.create_cmake_build_flags_str()}'
     return package_manager.run_cmd(build_cmd)
 
 
diff --git a/bootstrap/package_manager.py b/bootstrap/package_manager.py
index 2cf6c629d..9d54b668d 100644
--- a/bootstrap/package_manager.py
+++ b/bootstrap/package_manager.py
@@ -4,6 +4,7 @@
 import os
 import pathlib
 import platform
+import shutil
 import subprocess
 import sys
 from enum import Enum
@@ -31,11 +32,35 @@ def _query_yes_no(question: str, no_confirm: bool) -> bool:
             print("Please respond with 'yes' or 'no' (or 'y' or 'n').")
 
 
+def _is_rust_installed() -> bool:
+    cargo_bin = os.path.expanduser("~/.cargo/bin")
+    search_path = os.environ.get("PATH", "") + os.pathsep + cargo_bin
+    rustc = shutil.which("rustc", path=search_path)
+    cargo = shutil.which("cargo", path=search_path)
+    if not rustc or not cargo:
+        return False
+
+    try:
+        subprocess.run([rustc, "--version"], check=True)
+        subprocess.run([cargo, "--version"], check=True)
+    except (subprocess.CalledProcessError, OSError):
+        return False
+    return True
+
+
 def _run_command_with_confirm(command: str, no_confirm: bool) -> bool:
     if _query_yes_no(f"Running {command}", no_confirm):
         return os.system(command) == 0
 
 
+def _install_rust_on_unix(no_confirm: bool) -> bool:
+    if _is_rust_installed():
+        return True
+    return _run_command_with_confirm(
+        "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- 
-y", no_confirm
+    )
+
+
 class PackageManager:
     def __init__(self, no_confirm):
         self.no_confirm = no_confirm
@@ -62,6 +87,19 @@ class PackageManager:
             return True
         return _run_command_with_confirm(f"{install_cmd} {dependencies_str}", 
self.no_confirm)
 
+    def _install_with_rust_toolchain(
+        self,
+        dependencies: dict[str, set[str]],
+        replace_dict: dict[str, set[str]],
+        install_cmd: str,
+    ) -> bool:
+        if not self._install(dependencies=dependencies, 
replace_dict=replace_dict, install_cmd=install_cmd):
+            return False
+        return "rust_toolchain" not in dependencies or 
self._install_rust_toolchain()
+
+    def _install_rust_toolchain(self) -> bool:
+        raise RuntimeError("NotImplementedException")
+
     def _get_installed_packages(self) -> set[str]:
         raise RuntimeError("NotImplementedException")
 
@@ -77,15 +115,20 @@ class PackageManager:
         return result.returncode == 0
 
 
-class BrewPackageManager(PackageManager):
+class UnixPackageManager(PackageManager):
+    def _install_rust_toolchain(self) -> bool:
+        return _install_rust_on_unix(self.no_confirm)
+
+
+class BrewPackageManager(UnixPackageManager):
     def __init__(self, no_confirm):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        return self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="brew install",
-            replace_dict={"patch": set()},
+            replace_dict={"patch": set(), "rust_toolchain": {"curl", "llvm"}},
         )
 
     def install_compiler(self) -> str:
@@ -104,15 +147,19 @@ class BrewPackageManager(PackageManager):
         return result.returncode == 0
 
 
-class AptPackageManager(PackageManager):
+class AptPackageManager(UnixPackageManager):
     def __init__(self, no_confirm):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        return self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="sudo apt install -y",
-            replace_dict={"libarchive": {"liblzma-dev"}, "python": 
{"libpython3-dev"}},
+            replace_dict={
+                "libarchive": {"liblzma-dev"},
+                "python": {"libpython3-dev"},
+                "rust_toolchain": {"curl", "libclang-dev", "clang"},
+            },
         )
 
     def _get_installed_packages(self) -> set[str]:
@@ -126,9 +173,9 @@ class AptPackageManager(PackageManager):
         return ""
 
 
-class DnfPackageManager(PackageManager):
+class DnfPackageManager(UnixPackageManager):
     def __init__(self, no_confirm, needs_epel):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
         self.needs_epel = needs_epel
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
@@ -136,10 +183,15 @@ class DnfPackageManager(PackageManager):
             install_cmd = "sudo dnf --enablerepo=crb install -y 
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm";
         else:
             install_cmd = "sudo dnf install -y"
-        return self._install(
+
+        rust_replacement_set = {"clang", "clang-devel"}
+        if not shutil.which("curl"):
+            rust_replacement_set.add("curl")
+
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd=install_cmd,
-            replace_dict={"python": {"python3-devel"}},
+            replace_dict={"python": {"python3-devel"}, "rust_toolchain": 
rust_replacement_set},
         )
 
     def _get_installed_packages(self) -> set[str]:
@@ -153,15 +205,15 @@ class DnfPackageManager(PackageManager):
         return ""
 
 
-class PacmanPackageManager(PackageManager):
+class PacmanPackageManager(UnixPackageManager):
     def __init__(self, no_confirm):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        return self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="sudo pacman --noconfirm -S",
-            replace_dict={},
+            replace_dict={"rust_toolchain": {"curl", "clang"}},
         )
 
     def _get_installed_packages(self) -> set[str]:
@@ -173,17 +225,18 @@ class PacmanPackageManager(PackageManager):
         return ""
 
 
-class ZypperPackageManager(PackageManager):
+class ZypperPackageManager(UnixPackageManager):
     def __init__(self, no_confirm):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        return self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="sudo zypper install -y",
             replace_dict={
                 "libarchive": {"libarchive-devel"},
                 "python": {"python3-devel"},
+                "rust_toolchain": {"curl", "clang", "clang-devel"},
             },
         )
 
@@ -212,15 +265,19 @@ class ZypperPackageManager(PackageManager):
         return ""
 
 
-class ApkPackageManager(PackageManager):
+class ApkPackageManager(UnixPackageManager):
     def __init__(self, no_confirm):
-        PackageManager.__init__(self, no_confirm)
+        UnixPackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        return self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="sudo apk add --no-cache",
-            replace_dict={"libarchive": {"libarchive-dev"}, "python": 
{"python3-dev"}},
+            replace_dict={
+                "libarchive": {"libarchive-dev"},
+                "python": {"python3-dev"},
+                "rust_toolchain": {"curl", "clang-dev"},
+            },
         )
 
     def _get_installed_packages(self) -> set[str]:
@@ -264,8 +321,13 @@ def _get_activate_venv_path():
 
 
 def _minifi_setup_env_str(vs_where_location: VsWhereLocation) -> str:
+    # _OLD_VIRTUAL_PATH is cleared after refreshenv, because the bootstrap 
usually runs in an already activated venv
+    # (see py_bootstrap.bat), so this variable is inherited from there, 
holding the PATH from before any packages were
+    # installed. If it is set, activate.bat restores PATH from it, discarding 
the PATH refreshed from the registry
+    # (e.g. the newly installed rustup's cargo bin directory). Clearing it 
makes activate.bat keep the refreshed PATH.
     return f"""
 call refreshenv
+set _OLD_VIRTUAL_PATH=
 call "{_get_activate_venv_path()}"
 call {_get_vs_dev_cmd(vs_where_location)}
 setlocal EnableDelayedExpansion
@@ -286,7 +348,7 @@ class ChocolateyPackageManager(PackageManager):
         PackageManager.__init__(self, no_confirm)
 
     def install(self, dependencies: dict[str, set[str]]) -> bool:
-        self._install(
+        return self._install_with_rust_toolchain(
             dependencies=dependencies,
             install_cmd="choco install -y",
             replace_dict={
@@ -301,9 +363,13 @@ class ChocolateyPackageManager(PackageManager):
                 "make": set(),
                 "m4": {"gnuwin32-m4"},
                 "perl": {"strawberryperl", "NASM"},
+                "rust_toolchain": {"rustup.install", "llvm"},
             },
         )
-        return True
+
+    def _install_rust_toolchain(self) -> bool:
+        command = "rustup default stable"
+        return not _query_yes_no(f"Running {command}", self.no_confirm) or 
self.run_cmd(command)
 
     def _get_installed_packages(self) -> set[str]:
         result = subprocess.run(["choco", "list"], text=True, 
capture_output=True, check=True)
diff --git a/bootstrap/system_dependency.py b/bootstrap/system_dependency.py
index 3f4bef2b0..02c34ef98 100644
--- a/bootstrap/system_dependency.py
+++ b/bootstrap/system_dependency.py
@@ -28,6 +28,8 @@ def _create_system_dependencies(minifi_options: 
MinifiOptions) -> dict[str, set[
         system_dependencies["libtool"] = {"libtool"}
     if minifi_options.is_enabled("ENABLE_PYTHON_SCRIPTING"):
         system_dependencies["python"] = {"python"}
+    if minifi_options.is_enabled("MINIFI_RUST"):
+        system_dependencies["rust_toolchain"] = set()
     if platform.system() == "Windows":
         system_dependencies["wixtoolset"] = {"wixtoolset"}
     return system_dependencies

Reply via email to