Skip to main content

A Python wrapper for Binaryen

Project description

Binaryen.py

Binaryen.py is a python wrapper for Binaryen. Use this to create, optimise and interpret WebAssembly binaries in python.

Installation

First make sure Binaryen is installed and accessible from your path. For Linux/MacOS it's recommended to install it from your package manager or homebrew (on MacOS). Alternatively, download precompiled binaries of Binaryen.

Install through PyPI.

pip install binaryen.py

Test

pytest --doctest-modules --doctest-continue-on-failure

Format

black --extend-exclude binaryen/_binaryen_cffi.py .

Docs

mkdocs serve

Updating the Python header file

Get the latest binaryen header file and binaries.

Comment out #include <stdbool.h>, #include <stddef.h> and #include <stdint.h>

cpp -nostdinc -E -P binaryen-c.h | sed '/^\/\//d; s/##//g; s/;;/;/g;' | tr '\n' ' ' | sed '1s/^[[:space:]]*//; s/  */ /g;s/; /;\n/g;' | sed '/^__attribute__((deprecated))/d' | clang-format -style "{ColumnLimit: 0}" > binaryen-py.h

This cleans up the header file and removes deprecated code

Replace Union types with the largest type of that Union. E.g.

struct BinaryenLiteral
{
  uintptr_t type;
  union
  {
    int32_t i32;
    int64_t i64;
    float f32;
    double f64;
    uint8_t v128[16];
    const char *func;
  };
};

Becomes

struct BinaryenLiteral
{
  uintptr_t type;
  uint8_t v128[16];
};

Build the cffi interface by running python binaryen_build.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

binaryen.py-0.0.2.tar.gz (19.0 MB view hashes)

Uploaded Source

Built Distribution

binaryen.py-0.0.2-py3-none-any.whl (19.1 MB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page