Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false

[*.{js,jsx,ts,tsx,css,scss,html,svelte,postcss,glsl,c,h}]
indent_size = 2
indent_style = tab
trim_trailing_whitespace = true
24 changes: 19 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")

# Options
set(DEBUG OFF CACHE BOOL "Build MLX42 in debug mode, enabling assertions")
set(GLFW_FETCH ON CACHE BOOL "Clone and install GLFW")
set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the lib")
# -----------------------------------------------------------------------------
option(BUILD_SHARED_LIBS "Build mlx42 as a shared library." OFF)
set(DEBUG OFF CACHE BOOL "Build MLX42 in debug mode, enabling assertions")
set(GLFW_FETCH ON CACHE BOOL "Clone and install GLFW")
set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the lib")

# Compile Options
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -99,7 +101,9 @@ add_custom_command(

# Sources
# -----------------------------------------------------------------------------
add_library(mlx42 STATIC
# The library type is now determined by the BUILD_SHARED_LIBS option.
# By default, it builds a STATIC library.
add_library(mlx42 # Changed from "add_library(mlx42 STATIC"

# Root
${SOURCE_DIR}/mlx_cursor.c
Expand Down Expand Up @@ -134,6 +138,16 @@ add_library(mlx42 STATIC
)
target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Add this block to control symbol visibility for shared library builds
if(BUILD_SHARED_LIBS)
set_target_properties(mlx42 PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
)
target_compile_definitions(mlx42 PRIVATE MLX42_BUILD_SHARED)
endif()


# Dependencies
# -----------------------------------------------------------------------------

Expand Down Expand Up @@ -192,4 +206,4 @@ install(TARGETS mlx42
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ You can pass build [options](./docs/index.md#available-options) to cmake, e.g: `

You can find an example makefile in the documentation [here](https://github.com/codam-coding-college/MLX42/blob/master/docs/Basics.md).

#### Bindings (Python, etc)
MLX42 currently has a [Python FFI binding](./ffi/python/README.md) available.
In order to get it working you need to build the library first as shown above.
The only change is that you need to enable the option `BUILD_SHARED_LIBS` when building with cmake:
```bash
cmake -B build -DBUILD_SHARED_LIBS=ON && cmake --build build --parallel
```

----

## For MacOS:
Expand Down
Binary file added docs/assets/python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
216 changes: 216 additions & 0 deletions ffi/python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[codz]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py.cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
# Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
# poetry.lock
# poetry.toml

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
# pdm.lock
# pdm.toml
.pdm-python
.pdm-build/

# pixi
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
# pixi.lock
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
# in the .venv directory. It is recommended not to include this directory in version control.
.pixi

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# Redis
*.rdb
*.aof
*.pid

# RabbitMQ
mnesia/
rabbitmq/
rabbitmq-data/

# ActiveMQ
activemq-data/

# SageMath parsed files
*.sage.py

# Environments
.env
.envrc
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
# .idea/

# Abstra
# Abstra is an AI-powered process automation framework.
# Ignore directories containing user credentials, local state, and settings.
# Learn more at https://abstra.io/docs
.abstra/

# Visual Studio Code
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
# and can be added to the global gitignore or merged into this file. However, if you prefer,
# you could uncomment the following to ignore the entire vscode folder
# .vscode/

# Ruff stuff:
.ruff_cache/

# PyPI configuration file
.pypirc

# Marimo
marimo/_static/
marimo/_lsp/
__marimo__/

# Streamlit
.streamlit/secrets.toml
30 changes: 30 additions & 0 deletions ffi/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Python Bindings for MLX42

This directory contains Python bindings for the MLX42 graphics library, allowing you to use MLX42 functionalities in Python applications (using ^=3.13).

## Building

```bash
git clone https://github.com/codam-coding-college/MLX42.git
cd MLX42
cmake -B build -DBUILD_SHARED_LIBS=ON && cmake --build build --parallel
```

Within MLX42's root directory, there is an example script located at `ffi/python/example.py`.
You can run this script to see how to use the Python bindings:

In case you have a static library (`libmlx42.a`), you can create a shared library from it using `clang` or `gcc`:
```bash
clang -shared -o libmlx42.so libmlx42.a
```

Afterwards, place the shared library in the `ffi/python/` directory:
```bash
# You can also move the shared library onto a system path
mv build/libmlx42.so ffi/python/libmlx42.so
cd ffi/python
python3 example.py
```

# Example Output
![Example Output](../../docs/assets/python.png)
Loading