Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port nextpnr-{ice40,ecp5} to WASI #447

Merged
merged 1 commit into from
May 24, 2020
Merged

Port nextpnr-{ice40,ecp5} to WASI #447

merged 1 commit into from
May 24, 2020

Conversation

whitequark
Copy link
Member

@whitequark whitequark commented May 23, 2020

This involves very few changes, all typical to WASM ports:

  • WASM doesn't currently support threads or atomics so those are disabled.
  • WASM doesn't currently support exceptions so the exception machinery is stubbed out.
  • WASM doesn't (and can't) have mmap(), so an emulation library is used. That library currently doesn't support MAP_SHARED flags, so MAP_PRIVATE is used instead.

There is also an update to bring ECP5 bbasm CMake rules to parity with iCE40 ones, since although it is possible to embed chipdb into nextpnr on WASM, a 200 MB WASM file has very few practical uses.

The README is not updated and there is no included toolchain file because at the moment it's not possible to build nextpnr with upstream boost and wasi-libc. Boost requires a patch (merged, will be available in boost 1.74.0), wasi-libc requires a few unmerged patches.


Nevertheless I will briefly describe in this PR how to build it.

  1. Download wasi-sdk-10 and set $WASI_SDK to the location where it's unpacked
  2. Check out wasi-libc
  3. Apply this patch to wasi-libc
  4. Build wasi-libc and note the location of sysroot/lib/wasm32-wasi/libwasi-emulated-mman.a
  5. Replace -lwasi-emulated-mman in CMakeLists.txt with the full path to libwasi-emulated-mman.a
  6. Download Boost 1.72.0, apply this patch and bootstrap B2
  7. Place this configuration into Boost root as project-config.jam (replacing <WASI-SDK> as appropriate) and run ./b2 threading=single link=static
  8. Build bba and nextpnr for the host (native) with -DUSE_C_EMBED=ON. This will fail because your compiler probably doesn't support #embed but that's ok
  9. Place this toolchain file into the target (WASM) build directory as Toolchain-WASI.cmake
  10. Run cmake .. -DCMAKE_TOOLCHAIN_FILE=Toolchain-WASI.cmake -DSTATIC_BUILD=ON -DBOOST_ROOT=<Boost root> -DIMPORT_EXECUTABLES=<host build directory>/ImportExecutables.cmake -DARCH=<arch> -DBUILD_GUI=OFF -DBUILD_PYTHON=OFF -DEXTERNAL_CHIPDB=ON -DEXTERNAL_CHIPDB_ROOT=/share/nextpnr
  11. Run make. You should have a nextpnr-<arch>.wasm now
  12. Pick a WASI runtime, say wasmtime, then run wasmtime run ./nextpnr-<arch>.wasm --dir . --mapdir /share/nextpnr/<arch>::<host build directory>/<arch>/chipdbs -- <args> where <args> are the normal nextpnr arguments

Copy link
Contributor

@daveshah1 daveshah1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @mmicko can you double check the CMake and mmap side of changes?

This involves very few changes, all typical to WASM ports:
  * WASM doesn't currently support threads or atomics so those are
    disabled.
  * WASM doesn't currently support exceptions so the exception
    machinery is stubbed out.
  * WASM doesn't (and can't) have mmap(), so an emulation library is
    used. That library currently doesn't support MAP_SHARED flags,
    so MAP_PRIVATE is used instead.

There is also an update to bring ECP5 bbasm CMake rules to parity
with iCE40 ones, since although it is possible to embed chipdb into
nextpnr on WASM, a 200 MB WASM file has very few practical uses.

The README is not updated and there is no included toolchain file
because at the moment it's not possible to build nextpnr with
upstream boost and wasi-libc. Boost requires a patch (merged, will
be available in boost 1.74.0), wasi-libc requires a few unmerged
patches.
@mmicko
Copy link
Member

mmicko commented May 24, 2020

@whitequark @daveshah1 LGTM as well, default behavior seams unaffected.

@daveshah1 daveshah1 merged commit f44498a into YosysHQ:master May 24, 2020
@whitequark
Copy link
Member Author

Updated instructions as of 2020-06-22:

  1. Download wasi-sdk-11 and set $WASI_SDK to the location where it's unpacked
  2. Download Boost 1.72.0, apply this patch and bootstrap B2
  3. Place this configuration into Boost root as project-config.jam (replacing <WASI-SDK> as appropriate) and run ./b2 threading=single link=static
  4. Build bba and nextpnr for the host (native) with -DUSE_C_EMBED=ON. This will fail because your compiler probably doesn't support #embed but that's ok
  5. Place this toolchain file into the target (WASM) build directory as Toolchain-WASI.cmake
  6. Run cmake .. -DCMAKE_TOOLCHAIN_FILE=Toolchain-WASI.cmake -DSTATIC_BUILD=ON -DBOOST_ROOT=<Boost root> -DIMPORT_EXECUTABLES=<host build directory>/ImportExecutables.cmake -DARCH=<arch> -DBUILD_GUI=OFF -DBUILD_PYTHON=OFF -DEXTERNAL_CHIPDB=ON -DEXTERNAL_CHIPDB_ROOT=/share/nextpnr
  7. Run make. You should have a nextpnr-<arch>.wasm now
  8. Pick a WASI runtime, say wasmtime, then run wasmtime run ./nextpnr-<arch>.wasm --dir . --mapdir /share/nextpnr/<arch>::<host build directory>/<arch>/chipdbs -- <args> where <args> are the normal nextpnr arguments

@whitequark whitequark deleted the wasi branch June 23, 2020 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants