View on GitHub

YoWASP

Unofficial WebAssembly-based packages for Yosys, nextpnr, and more

A FOSSi Foundation project

This is the most galaxy brained solution to windows package distribution I've seen yet, I'm impressed and horrified @Amyayash

What is YoWASP?

YoWASP (Yosys WebAssembly Synthesis & PnR) is a project that aims to distribute up-to-date FOSS FPGA tools compiled to WebAssembly via language package managers like Python’s PyPI and JavaScript’s NPM.

Why use WebAssembly?

A batch compiler, such as an FPGA toolchain, transforms input files to output files without using any OS services beyond basic bookkeeping. Is it really necessary to build something so fundamentally simple for a large matrix of every OS × every CPU? With WebAssembly and WASI, it is now possible to build a single universal binary that runs on many OSes and CPUs.

Do I need a browser?

Despite the name, WebAssembly is not tied to browsers; it is a kind of machine code that can be easily translated into x86, ARM, or other machine code that your CPU runs directly. The tools provided by the YoWASP project can run directly on top of an operating system as well as within a browser environment. The project also provides an extension for Visual Studio Code, an editor built on top of browser technology.

Why use language package managers?

Many new hardware definition languages are embedded in another host language, which comes with its own package manager and repository. For example, Amaranth HDL is embedded in Python, which uses pip and PyPI. There are several benefits in distributing FPGA tools via language package managers:

Which tools are provided?

This project provides packages for:

Which platforms are supported?

Python embedding

YoWASP Python relies on a WebAssembly engine to run the Wasm code, and inherits both its advantages and its limitations.

At the moment, YoWASP Python uses the Wasmtime engine, which supports the following platforms:

Browser/Node.js embedding

YoWASP JavaScript relies on the WebAssembly engine in the browser or Node.js to run the Wasm code. Any version of a major browser or Node.js released within the last several years offers full support for WebAssembly.

Are there other packages?

YoWASP isn’t the only project that packages the open-source FPGA toolchain, and it has some limitations. One of the following projects may suit your workflow better:

How do I use the tools…

… with Python?

To use Yosys, install the yowasp-yosys package using pip or add it as a dependency. It provides the yowasp-yosys, yowasp-sby, and yowasp-yosys-smtbmc executables.

To use Boolector, install the yowasp-boolector package using pip or add it as a dependency. It provides the yowasp-boolector executable.

To use nextpnr-ice40, install the yowasp-nextpnr-ice40 package using pip or add it as a dependency. This package contains support for every device, and provides the yowasp-nextpnr-ice40, yowasp-icepack, yowasp-iceunpack, yowasp-icebram, yowasp-icemulti, and yowasp-icepll executables.

To use nextpnr-ecp5, install the yowasp-nextpnr-ecp5 package using pip or add it as a dependency. This package contains support for every device, and provides the yowasp-nextpnr-ecp5, yowasp-ecppack, yowasp-ecpunpack, yowasp-ecpbram, yowasp-ecpmulti, and yowasp-ecppll executables.

To use nextpnr-machxo2, install the yowasp-nextpnr-machxo2 package using pip or add it as a dependency. This package contains support for every device, and provides the yowasp-nextpnr-machxo2, yowasp-xo2pack, yowasp-xo2unpack, yowasp-xo2bram, yowasp-xo2multi, and yowasp-xo2pll executables. The yowasp-xo2* executables are bit-for-bit identical to the yowasp-ecp* executables above, but are renamed to avoid a conflict during installation.

To use nextpnr-nexus, install the yowasp-nextpnr-nexus package using pip or add it as a dependency. This package contains support for every device, and provides the yowasp-nextpnr-nexus and yowasp-prjoxide executables.

To use nextpnr-gowin, install the yowasp-nextpnr-gowin package using pip or add it as a dependency. This package contains support for every device, and provides the yowasp-nextpnr-gowin executable. It also depends on a compatible version of the Apicula package, which provides the gowin_pack and gowin_unpack executables.

Try running e.g. yowasp-yosys --version to see if everything works! When the tools are run for the first time, it will take a few seconds for them to be compiled to machine code.

If the packages are installed in a virtualenv, they will only be available in that virtual environment. Otherwise, they will be available system-wide or user-wide, similar to any other Python scripts installed via pip.

Consider also using PDM, which conveniently provides a way to set the required environment variables automatically in the pyproject.toml file…

[project]
...
dependencies = [
    "yowasp-yosys",
    "yowasp-nextpnr-ice40",
]

[tool.pdm.scripts]
_.env_file = ".env.toolchain"
...

… together with a .env.toolchain file…

YOSYS=yowasp-yosys
NEXTPNR_ICE40=yowasp-nextpnr-ice40
ICEPACK=yowasp-icepack

… such that they are set for any command run with pdm run <command>.

… in a browser?

These instructions assume the use of ES Modules, and make use of the jsDelivr content delivery network. It is also possible to distribute the YoWASP binaries by adding the relevant @yowasp/* NPM package as a dependency using a bundler such as webpack.

To use Yosys, import the @yowasp/yosys NPM package from the CDN and call its runYosys entry point:

import { runYosys } from 'https://cdn.jsdelivr.net/npm/@yowasp/yosys/gen/bundle.js';
await runYosys(["--version"]);

The JavaScript runtime README describes how to transfer files to and from the application.

… within Node.js?

These instructions assume the use of ES Modules.

To use Yosys, install the @yowasp/yosys NPM package as a dependency, which can be done by running npm install @yowasp/yosys, import it and call its runYosys entry point:

import { runYosys } from '@yowasp/yosys';
await runYosys(["--version"]);

The JavaScript runtime README describes how to transfer files to and from the application.

… with other languages?

At the moment, only PyPI and NPM packages are provided. Open an issue if you’d like YoWASP packages to be built for another ecosystem.

Are the tools slower?

Yosys built for WebAssembly is about half the speed of a native build. Nextpnr built for WebAssembly runs about as fast as a native build.

How are the packages released?

Routine YoWASP maintenance is fully automated. Upstream changes and releases are tracked daily without manual intervention.