From d40647bd10e94b67275a7328ec51f3f34fe22836 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 17:57:40 +0100 Subject: [PATCH 01/20] (wip) cross compilation Need to set CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER and compile with --target=arm-unknown-linux-gnueabihf working on optimizer_builder.py --- open-codegen/opengen/builder/optimizer_builder.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/open-codegen/opengen/builder/optimizer_builder.py b/open-codegen/opengen/builder/optimizer_builder.py index 8a43c30d..4c557436 100644 --- a/open-codegen/opengen/builder/optimizer_builder.py +++ b/open-codegen/opengen/builder/optimizer_builder.py @@ -123,6 +123,8 @@ def __make_build_command(self): if self.__build_config.target_system is not None: command.append('--target='+self.__build_config.target_system) + if self.__build_config.target_system in ["arm-unknown-linux-gnueabihf", "rpi"]: + os.environ['CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER'] = 'arm-linux-gnueabihf-gcc' return command @@ -571,7 +573,7 @@ def __generate_build_rs(self): def __build_optimizer(self): target_dir = os.path.abspath(self.__target_dir()) command = self.__make_build_command() - p = subprocess.Popen(command, cwd=target_dir) + p = subprocess.Popen(command, cwd=target_dir, shell=False) process_completion = p.wait() if process_completion != 0: raise Exception('Rust build failed') @@ -682,7 +684,7 @@ def __generate_code_python_bindings(self): cargo_config_file = os.path.join( og_dfn.templates_dir(), 'python', 'cargo_config') shutil.copy(cargo_config_file, os.path.join( - target_cargo_config_dir, 'config')) + target_cargo_config_dir, 'config.toml')) def __generate_code_tcp_interface(self): self.__logger.info( From 306f79e561768c7630f7df5f5a5a3967b7359aa0 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 18:28:58 +0100 Subject: [PATCH 02/20] update CI: remove ubuntu-20.04 (depr.) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c284a26e..f708b69c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, ubuntu-latest] + os: [ubuntu-latest] env: DO_DOCKER: 0 steps: From 478224925a3392aa74fc61715ac373187028d4ed Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 19:05:10 +0100 Subject: [PATCH 03/20] cross compilation issue fixed --- open-codegen/CHANGELOG.md | 7 ++++ .../opengen/builder/optimizer_builder.py | 35 ++++++++++++++----- .../opengen/templates/cargo_config.toml | 25 +++++++++++++ 3 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 open-codegen/opengen/templates/cargo_config.toml diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 59843c4b..498fb28a 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Note: This is the Changelog file of `opengen` - the Python interface of OpEn +## [0.10.0] - Unreleased + +## Changed + +- Fix issues with cross compilation (each sub-project has its own `.cargo/config.toml`) +- Rename auto-generated bindings file from `.cargo/config` to `.cargo/config.toml` + ## [0.9.3] - 2024-12-06 diff --git a/open-codegen/opengen/builder/optimizer_builder.py b/open-codegen/opengen/builder/optimizer_builder.py index 4c557436..7ee74680 100644 --- a/open-codegen/opengen/builder/optimizer_builder.py +++ b/open-codegen/opengen/builder/optimizer_builder.py @@ -123,8 +123,6 @@ def __make_build_command(self): if self.__build_config.target_system is not None: command.append('--target='+self.__build_config.target_system) - if self.__build_config.target_system in ["arm-unknown-linux-gnueabihf", "rpi"]: - os.environ['CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER'] = 'arm-linux-gnueabihf-gcc' return command @@ -162,8 +160,6 @@ def __prepare_target_project(self): """Creates folder structure Creates necessary folders - Runs `cargo init` in that folder - """ self.__logger.info("Creating necessary folders") @@ -175,6 +171,13 @@ def __prepare_target_project(self): os.makedirs(target_dir) else: make_dir_if_not_exists(target_dir) + + # make folder {root}/.cargo + dot_cargo_dir = os.path.join(target_dir, ".cargo") + make_dir_if_not_exists(dot_cargo_dir) + # copy cargo_config.toml into .cargo/config.toml + cargo_config_file = os.path.join(og_dfn.templates_dir(), 'cargo_config.toml') + shutil.copy(cargo_config_file, os.path.join(dot_cargo_dir, 'config.toml')) def __copy_icasadi_to_target(self): """ @@ -183,13 +186,21 @@ def __copy_icasadi_to_target(self): self.__logger.info("Copying icasadi interface to target directory") origin_icasadi_dir = og_dfn.original_icasadi_dir() target_icasadi_dir = self.__icasadi_target_dir() - if not os.path.exists(target_icasadi_dir): - os.makedirs(target_icasadi_dir) - shutil.rmtree(target_icasadi_dir) + target_icasadi_cargo_config_dir = os.path.join(target_icasadi_dir, ".cargo") + + if os.path.exists(target_icasadi_dir): + shutil.rmtree(target_icasadi_dir) + shutil.copytree(origin_icasadi_dir, target_icasadi_dir, ignore=shutil.ignore_patterns( '*.lock', 'ci*', 'target', 'auto*')) + + # Copy cargo_config.toml into .cargo/config.toml + make_dir_if_not_exists(target_icasadi_cargo_config_dir) + cargo_config_file = os.path.join(og_dfn.templates_dir(), 'cargo_config.toml') + shutil.copy(cargo_config_file, os.path.join( + target_icasadi_cargo_config_dir, 'config.toml')) def __generate_icasadi_cargo_toml(self): """ @@ -696,10 +707,12 @@ def __generate_code_tcp_interface(self): tcp_iface_dir_name = _TCP_IFACE_PREFIX + self.__meta.optimizer_name tcp_iface_dir = os.path.join(target_dir, tcp_iface_dir_name) tcp_iface_source_dir = os.path.join(tcp_iface_dir, "src") + tcp_iface_cargo_config_dir = os.path.join(tcp_iface_dir, ".cargo") # make tcp_iface/ and tcp_iface/src make_dir_if_not_exists(tcp_iface_dir) make_dir_if_not_exists(tcp_iface_source_dir) + make_dir_if_not_exists(tcp_iface_cargo_config_dir) # generate tcp_server.rs for tcp_iface tcp_rs_template = OpEnOptimizerBuilder.__get_template( @@ -720,6 +733,12 @@ def __generate_code_tcp_interface(self): target_tcp_rs_path = os.path.join(tcp_iface_dir, "Cargo.toml") with open(target_tcp_rs_path, "w") as fh: fh.write(tcp_rs_output_template) + + # Copy cargo_config.toml into .cargo/config.toml + cargo_config_file = os.path.join( + og_dfn.templates_dir(), 'cargo_config.toml') + shutil.copy(cargo_config_file, os.path.join( + tcp_iface_cargo_config_dir, 'config.toml')) def __generate_yaml_data_file(self): self.__logger.info("Generating YAML configuration file") @@ -852,7 +871,7 @@ def build(self): """ self.__initialize() # initialize default value (if not provided) self.__check_user_provided_parameters() # check the provided parameters - self.__prepare_target_project() # create folders; init cargo project + self.__prepare_target_project() # create folders self.__copy_icasadi_to_target() # copy icasadi/ files to target dir self.__generate_icasadi_cargo_toml() # generate icasadi's Cargo.toml file self.__generate_cargo_toml() # generate Cargo.toml using template diff --git a/open-codegen/opengen/templates/cargo_config.toml b/open-codegen/opengen/templates/cargo_config.toml new file mode 100644 index 00000000..7ded92cd --- /dev/null +++ b/open-codegen/opengen/templates/cargo_config.toml @@ -0,0 +1,25 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Autogenerated Cargo.toml configuration file +# This file was generated by OptimizationEngine +# +# See https://alphaville.github.io/optimization-engine/ +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +[target.x86_64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] + +[target.aarch64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] + +# This is for cross-compiling to ARM architecture (e.g., Raspberry Pi) +[target.arm-unknown-linux-gnueabihf] +linker="arm-linux-gnueabihf-gcc" From 8bf922d7fb14eae4cf3ee5bb63426dd56a75694f Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:10:48 +0100 Subject: [PATCH 04/20] update ubuntu-20.04 to ubuntu-latest --- .github/workflows/dox.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dox.yml b/.github/workflows/dox.yml index 2ebe1d25..f23c2214 100644 --- a/.github/workflows/dox.yml +++ b/.github/workflows/dox.yml @@ -8,7 +8,7 @@ on: jobs: deploy: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 28bf8e2fcb9e720aa8f98a0d8931129862b19134 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:20:23 +0100 Subject: [PATCH 05/20] cross compilation test --- ci/script.sh | 5 +++ open-codegen/test/test_raspberry_pi.py | 43 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 open-codegen/test/test_raspberry_pi.py diff --git a/ci/script.sh b/ci/script.sh index 91a72407..f9e68a43 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -44,10 +44,15 @@ regular_test() { # --- install opengen pip install . + # --- rust dependencies + rustup update + rustup target add arm-unknown-linux-gnueabihf + # --- run the tests export PYTHONPATH=. python -W ignore test/test_constraints.py -v python -W ignore test/test.py -v + python -W ignore test/test_raspberry_pi.py -v # Run Clippy for generated optimizers diff --git a/open-codegen/test/test_raspberry_pi.py b/open-codegen/test/test_raspberry_pi.py new file mode 100644 index 00000000..e6236241 --- /dev/null +++ b/open-codegen/test/test_raspberry_pi.py @@ -0,0 +1,43 @@ +import opengen as og +import unittest +import casadi.casadi as cs +import numpy as np +import math + + +class RaspberryPiTest(unittest.TestCase): + + # ----------------------------------------------------------------------- + # Cross-compile to Raspberry Pi + # ----------------------------------------------------------------------- + def test_compile_rpi(self): + optimizers_dir = "my_optimizers" + optimizer_name = "rosenbrock" + nu, np = 5, 2 + u = cs.SX.sym("u", nu) # decision variable (nu = 5) + p = cs.SX.sym("p", np) # parameter (np = 2) + phi = og.functions.rosenbrock(u, p) + 1500*cs.sum1(u) + c_f2 = cs.vertcat(0.2 + 1.5 * u[0] - u[1], u[2] - u[3] - 0.1) + bounds = og.constraints.Ball2(None, 1.5) + problem = og.builder.Problem(u, p, phi) \ + .with_penalty_constraints(c_f2)\ + .with_constraints(bounds) + meta = og.config.OptimizerMeta()\ + .with_optimizer_name(optimizer_name) + build_config = og.config.BuildConfiguration() \ + .with_build_directory(optimizers_dir) \ + .with_build_mode(og.config.BuildConfiguration.DEBUG_MODE) \ + .with_tcp_interface_config() \ + .with_target_system("rpi") + solver_cfg = og.config.SolverConfiguration() \ + .with_penalty_weight_update_factor(1.5) \ + .with_preconditioning(True) + builder = og.builder.OpEnOptimizerBuilder(problem, + meta, + build_config, + solver_cfg) + builder.build() + + +if __name__ == '__main__': + unittest.main() From c9646f4fbc8539ccfe0eaa3f50b565bd12fdd41e Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:35:43 +0100 Subject: [PATCH 06/20] configure CI (rpi target) --- .github/workflows/ci.yml | 18 ++++++++++++++++-- ci/script.sh | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f708b69c..96f29dbe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,8 +28,22 @@ jobs: with: python-version: '3.12' architecture: 'x64' - - run: cargo test --features rp - - run: cargo test --features jem + - name: Install ARM cross-compiler and C libraries + run: | + sudo apt-get update + sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross + # If icasadi_rosenbrock or other deps need C++: + # sudo apt-get install -y g++-arm-linux-gnueabihf + - name: Build for arm-unknown-linux-gnueabihf + # Set environment variables for the cc crate + env: + CC_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc + AR_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-ar + # If C++ is involved and you installed g++-arm-linux-gnueabihf: + # CXX_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++ + run: cargo build --target=arm-unknown-linux-gnueabihf --verbose + # - run: cargo test --features rp + # - run: cargo test --features jem - run: bash ./ci/script.sh ci_macos: diff --git a/ci/script.sh b/ci/script.sh index f9e68a43..7b812b45 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -50,8 +50,8 @@ regular_test() { # --- run the tests export PYTHONPATH=. - python -W ignore test/test_constraints.py -v - python -W ignore test/test.py -v + # python -W ignore test/test_constraints.py -v + # python -W ignore test/test.py -v python -W ignore test/test_raspberry_pi.py -v From 26bd0a09b46b0e4905e190fb3338927e2cbf1afe Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:39:00 +0100 Subject: [PATCH 07/20] fix issue in CI --- .github/workflows/ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96f29dbe..6c1deea2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,17 +34,17 @@ jobs: sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross # If icasadi_rosenbrock or other deps need C++: # sudo apt-get install -y g++-arm-linux-gnueabihf - - name: Build for arm-unknown-linux-gnueabihf + - name: Run tests # Set environment variables for the cc crate env: CC_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc AR_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-ar # If C++ is involved and you installed g++-arm-linux-gnueabihf: # CXX_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++ - run: cargo build --target=arm-unknown-linux-gnueabihf --verbose - # - run: cargo test --features rp - # - run: cargo test --features jem - - run: bash ./ci/script.sh + run: | + # - run: cargo test --features rp + # - run: cargo test --features jem + bash ./ci/script.sh ci_macos: runs-on: ${{ matrix.os }} From e98033c42d0018d81e1c078a10b983a86174abcb Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:45:30 +0100 Subject: [PATCH 08/20] fix CI issues --- .github/workflows/ci.yml | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c1deea2..17f9d10c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,10 @@ jobs: sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross # If icasadi_rosenbrock or other deps need C++: # sudo apt-get install -y g++-arm-linux-gnueabihf + - name: Cargo tests (RP and JEM) + run: | + cargo test --features rp + cargo test --features jem - name: Run tests # Set environment variables for the cc crate env: @@ -41,9 +45,7 @@ jobs: AR_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-ar # If C++ is involved and you installed g++-arm-linux-gnueabihf: # CXX_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++ - run: | - # - run: cargo test --features rp - # - run: cargo test --features jem + run: | bash ./ci/script.sh ci_macos: @@ -69,4 +71,30 @@ jobs: python-version: '3.12' - run: cargo test --features rp - run: cargo test --features jem - - run: bash ./ci/script.sh + - name: Install ARM cross-compiler toolchain (via Homebrew) + run: | + # Tap the repository that provides the cross-compiler + brew tap messense/macos-cross-toolchains + # Update brew to ensure the tap is recognized (can sometimes be needed) + brew update + # Install the full toolchain (includes gcc, binutils, sysroot) + # This specific formula provides the entire toolchain. + brew install arm-unknown-linux-gnueabihf + + # The above `brew install` might have linking conflicts if other partial + # toolchains were somehow pre-installed or installed by other steps. + # If it fails with link errors, you might need: + # brew link --overwrite arm-unknown-linux-gnueabihf + + # Verify the compiler is found + which arm-linux-gnueabihf-gcc || (echo "arm-linux-gnueabihf-gcc not found in PATH" && exit 1) + - name: Build for arm-unknown-linux-gnueabihf + # Set environment variables for the cc crate and PyO3 (if needed) + env: + CC_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc + AR_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-ar + # If you are building PyO3 bindings and need to specify Python libs from the sysroot: + # PYO3_CROSS_LIB_DIR: "/opt/homebrew/opt/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/lib" # Adjust path and Python version + # PYO3_CROSS_INCLUDE_DIR: "/opt/homebrew/opt/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/include/python3.x" # Adjust path and Python version + run: | + bash ./ci/script.sh From f01f42468a9b4b7b14a10e89cd0ff635ae1eb072 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 21:48:24 +0100 Subject: [PATCH 09/20] forgot to uncomment the tests --- ci/script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/script.sh b/ci/script.sh index 7b812b45..f9e68a43 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -50,8 +50,8 @@ regular_test() { # --- run the tests export PYTHONPATH=. - # python -W ignore test/test_constraints.py -v - # python -W ignore test/test.py -v + python -W ignore test/test_constraints.py -v + python -W ignore test/test.py -v python -W ignore test/test_raspberry_pi.py -v From 4aef6623acd04a3f40d2ecfbb67859a1c91a778d Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 22:07:01 +0100 Subject: [PATCH 10/20] website docs on targets --- docs/python-advanced.md | 61 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/docs/python-advanced.md b/docs/python-advanced.md index ccf45165..ef8c4756 100644 --- a/docs/python-advanced.md +++ b/docs/python-advanced.md @@ -99,8 +99,10 @@ build_config.with_build_mode( og.config.BuildConfiguration.RELEASE_MODE) ``` +### Cross-compilation + You can either compile for your own system, or cross-compile for a -different target system. For example, to cross-compile for a Raspberry Pi, +different target system. For example, to cross-compile for a **Raspberry Pi**, set the following option ```python @@ -113,8 +115,63 @@ or build_config.with_target_system("rpi") # Raspberry Pi ``` -Note that you need to install the necessary target first. +Note that you need to install the necessary target first. + +
+See setup details +To cross-compile for a Raspberry Pi you need to run the following in your terminal + +```bash +rustup target add arm-unknown-linux-gnueabihf +``` + +On Linux you also need the following dependencies + +```bash +sudo apt-get update +sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross +``` + +On MacOS, do the following + +```bash +# Tap the repository that provides the cross-compiler +brew tap messense/macos-cross-toolchains +# Update brew to ensure the tap is recognized (can sometimes be needed) +brew update +# Install the full toolchain (includes gcc, binutils, sysroot) +# This specific formula provides the entire toolchain. +brew install arm-unknown-linux-gnueabihf + +# Verify the compiler is found +which arm-linux-gnueabihf-gcc || (echo "arm-linux-gnueabihf-gcc not found in PATH" && exit 1) +``` +
+ +If you need to compile for a target other than `arm-linux-gnueabihf-gcc` (`rpi`) +some manual configuration may be needed (you may need to install the target +and/or a compiler/linker) and you may need to edit the auto-generated +`.cargo/config.toml` files you will find in your auto-generated solvers. + +
+Non-supported targets +The auto-generated `.cargo/config.toml` files contain entries like + +```toml +[target.arm-unknown-linux-gnueabihf] +linker="arm-linux-gnueabihf-gcc" +``` + +Here you may have to insert manually your own target. +Feel free to open an [issue](https://github.com/alphaville/optimization-engine/issues) +on GitHub if you would like us to add support for a particular target (create a feature +request); see the [contributing guidelines](https://alphaville.github.io/optimization-engine/docs/contributing). +
+ + +### Other build options +All build options are shown below | Method | Explanation | |-------------------------------|---------------------------------------------| From 393e5a725df9bf570bc61c7b70bebf897ba07165 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 22:08:06 +0100 Subject: [PATCH 11/20] update website --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17f9d10c..33922b3b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: run: | cargo test --features rp cargo test --features jem - - name: Run tests + - name: Run tests (script.sh) # Set environment variables for the cc crate env: CC_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc @@ -88,7 +88,7 @@ jobs: # Verify the compiler is found which arm-linux-gnueabihf-gcc || (echo "arm-linux-gnueabihf-gcc not found in PATH" && exit 1) - - name: Build for arm-unknown-linux-gnueabihf + - name: Run tests (script.sh) # Set environment variables for the cc crate and PyO3 (if needed) env: CC_arm_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc From 85b19890f69b8005fe3a966e5c387f9b01930c1c Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 22:13:32 +0100 Subject: [PATCH 12/20] use code tabs (docusaurus) --- docs/python-advanced.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/python-advanced.md b/docs/python-advanced.md index ef8c4756..1d2760df 100644 --- a/docs/python-advanced.md +++ b/docs/python-advanced.md @@ -125,15 +125,17 @@ To cross-compile for a Raspberry Pi you need to run the following in your termin rustup target add arm-unknown-linux-gnueabihf ``` -On Linux you also need the following dependencies +You also need to install the following dependencies + + + ```bash sudo apt-get update sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross ``` -On MacOS, do the following - + ```bash # Tap the repository that provides the cross-compiler brew tap messense/macos-cross-toolchains @@ -146,8 +148,10 @@ brew install arm-unknown-linux-gnueabihf # Verify the compiler is found which arm-linux-gnueabihf-gcc || (echo "arm-linux-gnueabihf-gcc not found in PATH" && exit 1) ``` + +
If you need to compile for a target other than `arm-linux-gnueabihf-gcc` (`rpi`) some manual configuration may be needed (you may need to install the target and/or a compiler/linker) and you may need to edit the auto-generated From 2a4458fdb0c2c793a83189d00a56558feed2fb54 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 23:36:34 +0100 Subject: [PATCH 13/20] update changelog (v0.10.0) --- open-codegen/CHANGELOG.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 498fb28a..1cd36281 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -7,11 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Note: This is the Changelog file of `opengen` - the Python interface of OpEn -## [0.10.0] - Unreleased +## [0.10.0] - 2025-05-07 -## Changed -- Fix issues with cross compilation (each sub-project has its own `.cargo/config.toml`) +### Fixed + +- Fixed issues with cross compilation (each sub-project has its own `.cargo/config.toml`) and updated [documentation](https://alphaville.github.io/optimization-engine/docs/python-advanced#cross-compilation) + +### Changed + - Rename auto-generated bindings file from `.cargo/config` to `.cargo/config.toml` @@ -233,6 +237,7 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn * Fixed `lbfgs` typo +[0.10.0]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.3...opengen-0.10.0 [0.9.3]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.2...opengen-0.9.3 [0.9.2]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.1...opengen-0.9.2 [0.9.1]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.0...opengen-0.9.1 From ac7135cc5c144184077eaa65f377f4f1e86d7f5c Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Tue, 6 May 2025 23:38:00 +0100 Subject: [PATCH 14/20] bump version, update changelog --- open-codegen/CHANGELOG.md | 4 ++-- open-codegen/VERSION | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 1cd36281..108cea13 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Note: This is the Changelog file of `opengen` - the Python interface of OpEn -## [0.10.0] - 2025-05-07 +## [0.9.4] - 2025-05-07 ### Fixed @@ -16,7 +16,7 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn ### Changed -- Rename auto-generated bindings file from `.cargo/config` to `.cargo/config.toml` +- Rename auto-generated bindings file from `.cargo/config` to `.cargo/config.toml` (backwards compatible change) ## [0.9.3] - 2024-12-06 diff --git a/open-codegen/VERSION b/open-codegen/VERSION index b3ec1638..2bd77c74 100644 --- a/open-codegen/VERSION +++ b/open-codegen/VERSION @@ -1 +1 @@ -0.9.3 \ No newline at end of file +0.9.4 \ No newline at end of file From c251c9b666fc314f697cb03d280ff928ce7daa46 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 7 May 2025 00:26:34 +0100 Subject: [PATCH 15/20] update website docs --- docs/python-advanced.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/python-advanced.md b/docs/python-advanced.md index 1d2760df..be36feb5 100644 --- a/docs/python-advanced.md +++ b/docs/python-advanced.md @@ -81,6 +81,8 @@ A complete list of solver options is given in the following table ## Build options +### Build mode + During the design phase, one needs to experiment with the problem formulation and solver parameters. This is way the default build mode is the "debug" mode, which compiles fast, but it suboptimal. @@ -173,6 +175,22 @@ request); see the [contributing guidelines](https://alphaville.github.io/optimiz +When cross-compiling for a Raspberry Pi you may want to configure a TCP server +so you can call the optimizer remotely. You can find more information about this +[below](#tcpip-interface). +Once you have cross-compiled, locate the file +```text +{your_optimizer}/tcp_iface_{your_optimizer}/target/arm-unknown-linux-gnueabihf/release/tcp_iface_{your_optimizer} +``` +—where `{your_optimizer}` is the name of your optimizer—and copy it to your Raspberry Pi. +On your Raspberry, change the permissions so you can execute this file +```bash +chmod u+x ./tcp_iface_{your_optimizer} +``` +and [run it](#tcpip-interface). Your OpEn server is live. +Read also the [documentation](https://alphaville.github.io/optimization-engine/docs/python-tcp-ip) +on the TCP sockets protocol of OpEn servers. + ### Other build options All build options are shown below From bf7af6cea4b2012290af96ec7da96ddc0fc36996 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 7 May 2025 02:38:07 +0100 Subject: [PATCH 16/20] update website docs and C/C++ bindings --- docs/python-advanced.md | 2 +- open-codegen/CHANGELOG.md | 2 ++ .../opengen/templates/c/example_cmakelists.txt | 2 +- .../templates/c/example_optimizer_c_bindings.c | 13 +++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/docs/python-advanced.md b/docs/python-advanced.md index be36feb5..9f679158 100644 --- a/docs/python-advanced.md +++ b/docs/python-advanced.md @@ -187,7 +187,7 @@ On your Raspberry, change the permissions so you can execute this file ```bash chmod u+x ./tcp_iface_{your_optimizer} ``` -and [run it](#tcpip-interface). Your OpEn server is live. +and [run it](https://alphaville.github.io/optimization-engine/docs/python-tcp-ip). Your OpEn server is live. Read also the [documentation](https://alphaville.github.io/optimization-engine/docs/python-tcp-ip) on the TCP sockets protocol of OpEn servers. diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 108cea13..d5b9958d 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -17,6 +17,8 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn ### Changed - Rename auto-generated bindings file from `.cargo/config` to `.cargo/config.toml` (backwards compatible change) +- Updated min cmake version from 2.8 to 3.5 +- Updated auto-generated example C/C++ bindings ## [0.9.3] - 2024-12-06 diff --git a/open-codegen/opengen/templates/c/example_cmakelists.txt b/open-codegen/opengen/templates/c/example_cmakelists.txt index d4da009c..13a79032 100644 --- a/open-codegen/opengen/templates/c/example_cmakelists.txt +++ b/open-codegen/opengen/templates/c/example_cmakelists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.5) # Project name project({{meta.optimizer_name}}) diff --git a/open-codegen/opengen/templates/c/example_optimizer_c_bindings.c b/open-codegen/opengen/templates/c/example_optimizer_c_bindings.c index 79895b15..64f3b69a 100644 --- a/open-codegen/opengen/templates/c/example_optimizer_c_bindings.c +++ b/open-codegen/opengen/templates/c/example_optimizer_c_bindings.c @@ -3,11 +3,20 @@ * * Compile with: * - * gcc -Wall -std=c99 -pedantic \ + * $ gcc -Wall -std=c99 -pedantic \ example_optimizer.c -l:lib{{meta.optimizer_name}}.a \ -L./target/{{build_config.build_mode}} -pthread -lm -ldl \ -o optimizer * + * OR ... + * + * $ gcc -Wall -std=c99 -pedantic \ + example_optimizer.c -l{{meta.optimizer_name}} \ + -L./target/{{build_config.build_mode}} -pthread -lm -ldl \ + -o optimizer + * + * Or simply do: + * cmake .; make run */ #include @@ -17,7 +26,7 @@ * Feel free to customize the following code... */ -int main() { +int main(void) { int i; /* parameters */ From 36d188b3dacbd976734238636fd5ce04af73b91a Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Wed, 7 May 2025 11:50:25 +0100 Subject: [PATCH 17/20] cleanup: remove unnecessary file --- open-codegen/opengen/builder/optimizer_builder.py | 4 ++-- open-codegen/opengen/templates/python/cargo_config | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) delete mode 100644 open-codegen/opengen/templates/python/cargo_config diff --git a/open-codegen/opengen/builder/optimizer_builder.py b/open-codegen/opengen/builder/optimizer_builder.py index 7ee74680..67956171 100644 --- a/open-codegen/opengen/builder/optimizer_builder.py +++ b/open-codegen/opengen/builder/optimizer_builder.py @@ -689,11 +689,11 @@ def __generate_code_python_bindings(self): with open(target_python_rs_path, "w") as fh: fh.write(python_rs_output_template) - # move cargo_config into .cargo/config + # copy cargo_config into .cargo/config target_cargo_config_dir = os.path.join(python_bindings_dir, '.cargo') make_dir_if_not_exists(target_cargo_config_dir) cargo_config_file = os.path.join( - og_dfn.templates_dir(), 'python', 'cargo_config') + og_dfn.templates_dir(), 'cargo_config.toml') shutil.copy(cargo_config_file, os.path.join( target_cargo_config_dir, 'config.toml')) diff --git a/open-codegen/opengen/templates/python/cargo_config b/open-codegen/opengen/templates/python/cargo_config deleted file mode 100644 index 49314f34..00000000 --- a/open-codegen/opengen/templates/python/cargo_config +++ /dev/null @@ -1,10 +0,0 @@ -[target.x86_64-apple-darwin] -rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", -] -[target.aarch64-apple-darwin] -rustflags = [ - "-C", "link-arg=-undefined", - "-C", "link-arg=dynamic_lookup", -] \ No newline at end of file From 9d487812a4bb73253eebd7e313f9629e75d7ee1c Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Thu, 8 May 2025 17:14:49 +0100 Subject: [PATCH 18/20] update changelog --- open-codegen/CHANGELOG.md | 2 +- website/package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index d5b9958d..55a861cc 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -239,7 +239,7 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn * Fixed `lbfgs` typo -[0.10.0]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.3...opengen-0.10.0 +[0.10.0]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.3...opengen-0.9.4 [0.9.3]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.2...opengen-0.9.3 [0.9.2]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.1...opengen-0.9.2 [0.9.1]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.0...opengen-0.9.1 diff --git a/website/package.json b/website/package.json index cec29100..06c92b34 100644 --- a/website/package.json +++ b/website/package.json @@ -16,5 +16,6 @@ }, "dependencies": { "remark-admonitions": "^1.2.1" - } + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" } From ba3d1c35de0e6d03345784de9a81d56b29e71308 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Thu, 8 May 2025 17:15:11 +0100 Subject: [PATCH 19/20] changelog: update release date --- open-codegen/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index 55a861cc..f364f894 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). Note: This is the Changelog file of `opengen` - the Python interface of OpEn -## [0.9.4] - 2025-05-07 +## [0.9.4] - 2025-05-08 ### Fixed From ef9656d8b79a850e31018c132dd73b98c30df074 Mon Sep 17 00:00:00 2001 From: Pantelis Sopasakis Date: Thu, 8 May 2025 17:15:41 +0100 Subject: [PATCH 20/20] fix changelog link --- open-codegen/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/open-codegen/CHANGELOG.md b/open-codegen/CHANGELOG.md index f364f894..ce7f82d7 100644 --- a/open-codegen/CHANGELOG.md +++ b/open-codegen/CHANGELOG.md @@ -239,7 +239,7 @@ Note: This is the Changelog file of `opengen` - the Python interface of OpEn * Fixed `lbfgs` typo -[0.10.0]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.3...opengen-0.9.4 +[0.9.4]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.3...opengen-0.9.4 [0.9.3]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.2...opengen-0.9.3 [0.9.2]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.1...opengen-0.9.2 [0.9.1]: https://github.com/alphaville/optimization-engine/compare/opengen-0.9.0...opengen-0.9.1