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.
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. |
- 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.bz2mpfr-4.2.2.tar.xzmpc-1.3.1.tar.gzflint-3.3.1.tar.gzsymengine-0.11.2.tar.gz
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.
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.
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); // trueTo 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:
- 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.
- XCFramework Integration: Packaging as XCFrameworks provides clean header access and simplifies integration with CocoaPods and Xcode.
- Unified Plugin: A single plugin,
symbolic_math_bridge, manages all five libraries, eliminating the need for multiple, separate packages.
This build system is one part of a complete mathematical computing solution for Flutter:
- math-stack-ios-builder (This Repository): Builds the XCFramework libraries.
- symbolic_math_bridge: The Flutter plugin that provides a unified Dart API to all libraries.
- math-stack-test: A demo Flutter app showcasing the complete functionality.
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.
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);- "Command not found" or "Permission Denied": Run
chmod +x build_*.shto 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.shscript or running the individual scripts in the correct order. - Symbol Linking Issues in Flutter ("symbol not found"):
- Verify the plugin's
.podspecincludes 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.
- Verify the plugin's
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.