Skip to content

CrispStrobe/math-stack-ios-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mathematical Computing Stack Builder for Flutter, and especially for iOS

A complete build system for compiling a powerful mathematical computing stack for Flutter, and especially, for modern Apple platforms. This project compiles GMP, MPFR, MPC, FLINT, and SymEngine into self-contained, static XCFrameworks that work on iOS devices, simulators (Intel and Apple Silicon), and macOS.

This provides a suite of tools for arbitrary-precision arithmetic, number theory, and symbolic manipulation directly within Apple ecosystem applications.


What This Builds

The build process creates five interdependent XCFrameworks. The final product, SymEngineFlutterWrapper.xcframework, bundles the SymEngine library with a C wrapper designed for seamless Flutter FFI integration.

Framework Library Purpose
GMP.xcframework GNU Multiple Precision 6.3.0 Arbitrary-precision integer arithmetic.
MPFR.xcframework Multiple-Precision Floating-Point 4.2.2 Correctly rounded arbitrary-precision floats.
MPC.xcframework Multiple-Precision Complex 1.3.1 Arbitrary-precision complex number arithmetic.
FLINT.xcframework Fast Library for Number Theory 3.3.1 Advanced number theory, polynomials, and matrices.
SymEngineFlutterWrapper.xcframework SymEngine 0.11.2 + Flutter C Wrapper Fast symbolic manipulation with a C FFI layer.

Requirements

  • macOS with Xcode and Command Line Tools installed.
  • CMake: Required for building SymEngine. Install via Homebrew: brew install cmake.
  • Source Archives: The following tarballs must be present in the project's root directory:
    • gmp-6.3.0.tar.bz2
    • mpfr-4.2.2.tar.xz
    • mpc-1.3.1.tar.gz
    • flint-3.3.1.tar.gz
    • symengine-0.11.2.tar.gz

Build Instructions

A master script, build_all.sh, handles the entire build process, running the individual library scripts in the correct dependency order.

# First, make all build scripts executable
chmod +x build_*.sh

# Run the master script to build the entire stack
./build_all.sh

# All five XCFrameworks have been created in the root directory.

The master script is the recommended way to build, as it ensures all dependencies are met. It simply automates the process of running each build_gmp.sh, build_mpfr.sh, etc., in the correct sequence.


Integration with Flutter

This project is the foundational component for the symbolic_math_bridge Flutter plugin. The generated XCFrameworks are consumed by the plugin, providing unified access to the entire math stack.

Unified Architecture

A single Flutter plugin provides access to all libraries, from high-level symbolic algebra down to low-level arbitrary-precision arithmetic.

// High-level symbolic computing (SymEngine)
final result = casBridge.evaluate('solve(x^2 - 1, x)');

// Direct arbitrary-precision integer arithmetic (GMP)
final bigInt = casBridge.gmpPower(2, 256); // 2^256

// Direct arbitrary-precision floating-point (MPFR) 
final pi = casBridge.mpfrGetPi(128); // 128-bit precision π

// Direct complex number arithmetic (MPC)
final complexResult = casBridge.mpcMultiply(3, 4, 1, 2); // (3+4i) * (1+2i)

// Direct number theory functions (FLINT)
final isPrime = casBridge.flintIsPrime(997); // true

The Symbol Linking Solution

To prevent the linker from stripping unused symbols from the static C libraries—a common issue in native integration—this system uses a simple and robust solution:

  1. Force Symbol Loading: The plugin's Objective-C bridge file contains direct references to key functions from all five libraries, ensuring they are linked into the final application binary.
  2. XCFramework Integration: Packaging as XCFrameworks provides clean header access and simplifies integration with CocoaPods and Xcode.
  3. Unified Plugin: A single plugin, symbolic_math_bridge, manages all five libraries, eliminating the need for multiple, separate packages.

Companion Repositories

This build system is one part of a complete mathematical computing solution for Flutter:


Technical Notes

Build Dependencies

The build order is critical and enforced by the build_all.sh script:

  • MPFR requires GMP.
  • MPC requires GMP and MPFR.
  • FLINT requires GMP and MPFR.
  • SymEngine requires GMP, MPFR, MPC, and FLINT.

SymEngine Flutter C Wrapper

The SymEngine build creates the core library and bundles it with a C wrapper that provides a simplified, FFI-friendly API. The function names are prefixed to avoid conflicts.

// C wrapper functions exposed for FFI
char* flutter_symengine_evaluate(const char* expression);
char* flutter_symengine_solve(const char* expression, const char* symbol);
char* flutter_symengine_expand(const char* expression);
// ... and many more ...
void flutter_symengine_free_string(char* str);

Troubleshooting

  • "Command not found" or "Permission Denied": Run chmod +x build_*.sh to make the build scripts executable.
  • "SDK path not found": Install the Xcode Command Line Tools via xcode-select --install.
  • Dependency Error (e.g., "GMP build not found"): Ensure you are using the build_all.sh script or running the individual scripts in the correct order.
  • Symbol Linking Issues in Flutter ("symbol not found"):
    • Verify the plugin's .podspec includes the necessary linker flags (-all_load).
    • Ensure the Objective-C bridge file includes references to force-load symbols.
    • Confirm all XCFrameworks are properly included in the plugin's Podspec.

License

This build system is released under the MIT License. The underlying mathematical libraries are available under their own open-source licenses (primarily LGPL), which you must comply with in your application.

About

build scripts for the gmp, mpfr, mpc, flint, symengine math libraries for ios

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •