Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed1cceb
commit 2ecd51e
Showing
9 changed files
with
190 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh -ex | ||
|
||
PYTHON=${PYTHON:-python} | ||
|
||
mkdir -p pypi-nexus/yowasp_nextpnr_nexus/bin/ | ||
cp prjoxide-build/wasm32-wasi/release/prjoxide.wasm \ | ||
nextpnr-build/nextpnr-nexus.wasm \ | ||
pypi-nexus/yowasp_nextpnr_nexus/ | ||
mkdir -p pypi-nexus/yowasp_nextpnr_nexus/share/nexus | ||
cp nextpnr-build/nexus/chipdb/*.bin \ | ||
pypi-nexus/yowasp_nextpnr_nexus/share/nexus | ||
|
||
cd pypi-nexus | ||
rm -rf build && ${PYTHON} setup.py bdist_wheel | ||
sha256sum dist/*.whl |
Submodule prjoxide-src
added at
67d385
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
__pycache__/ | ||
/*.egg-info | ||
/.eggs | ||
/build | ||
/dist | ||
|
||
/yowasp_*/share |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import os | ||
from setuptools import setup, find_packages | ||
from setuptools_scm.git import parse as parse_git | ||
|
||
|
||
def version(): | ||
upstream_git = parse_git("../nextpnr-src") | ||
if upstream_git.exact: | ||
nextpnr_version = upstream_git.format_with("{tag}") | ||
else: | ||
nextpnr_version = upstream_git.format_with("{tag}.post{distance}") | ||
|
||
package_git = parse_git("..") | ||
if not package_git.dirty: | ||
package_version = package_git.format_with(".dev{distance}") | ||
else: | ||
package_version = package_git.format_with(".dev{distance}+dirty") | ||
|
||
return nextpnr_version + package_version | ||
|
||
|
||
def long_description(): | ||
with open("../README.md") as f: | ||
return f.read() | ||
|
||
|
||
setup_info = dict( | ||
name="yowasp-nextpnr-nexus", | ||
version=version(), | ||
install_requires=[ | ||
"importlib_resources; python_version<'3.9'", | ||
"appdirs~=1.4", | ||
"wasmtime>=0.20,<0.28" | ||
], | ||
packages=["yowasp_nextpnr_nexus"], | ||
package_data={ | ||
"yowasp_nextpnr_nexus": [ | ||
"*.wasm", | ||
"share/nexus/chipdb-*.bin", | ||
], | ||
}, | ||
entry_points={ | ||
"console_scripts": [ | ||
"yowasp-prjoxide = yowasp_nextpnr_nexus:_run_prjoxide_argv", | ||
"yowasp-nextpnr-nexus = yowasp_nextpnr_nexus:_run_nextpnr_nexus_argv", | ||
], | ||
}, | ||
) | ||
|
||
|
||
setup( | ||
author="whitequark", | ||
author_email="whitequark@whitequark.org", | ||
description="nextpnr-nexus FPGA place and route tool", | ||
long_description=long_description(), | ||
long_description_content_type="text/markdown", | ||
license="ISC", # same as Yosys | ||
python_requires="~=3.5", | ||
setup_requires=["setuptools_scm", "wheel"], | ||
**setup_info, | ||
project_urls={ | ||
"Homepage": "https://yowasp.github.io/", | ||
"Source Code": "https://github.com/YoWASP/nextpnr", | ||
"Bug Tracker": "https://github.com/YoWASP/nextpnr/issues", | ||
}, | ||
classifiers=[ | ||
"License :: OSI Approved :: ISC License (ISCL)", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import sys | ||
import wasmtime | ||
import pathlib | ||
import hashlib | ||
import appdirs | ||
try: | ||
from importlib import resources as importlib_resources | ||
try: | ||
importlib_resources.files # py3.9+ stdlib | ||
except AttributeError: | ||
import importlib_resources # py3.8- shim | ||
except ImportError: | ||
import importlib_resources # py3.6- shim | ||
|
||
|
||
def _run_wasm_app(wasm_filename, argv): | ||
module_binary = importlib_resources.read_binary(__package__, wasm_filename) | ||
module_digest = hashlib.sha1(module_binary).digest() | ||
|
||
wasi_cfg = wasmtime.WasiConfig() | ||
wasi_cfg.argv = argv | ||
wasi_cfg.preopen_dir(str(importlib_resources.files(__package__) / "share"), "/share") | ||
wasi_cfg.preopen_dir("/", "/") | ||
wasi_cfg.preopen_dir(".", ".") | ||
wasi_cfg.inherit_stdin() | ||
wasi_cfg.inherit_stdout() | ||
wasi_cfg.inherit_stderr() | ||
|
||
engine = wasmtime.Engine() | ||
cache_path = pathlib.Path(os.getenv("YOWASP_CACHE_DIR", appdirs.user_cache_dir("yowasp"))) | ||
cache_path.mkdir(parents=True, exist_ok=True) | ||
cache_filename = (cache_path / "{}-cache".format(wasm_filename)) | ||
digest_filename = (cache_path / "{}-digest".format(wasm_filename)) | ||
try: | ||
with digest_filename.open("rb") as digest_file: | ||
if digest_file.read() != module_digest: | ||
raise Exception("cache miss") | ||
with cache_filename.open("rb") as cache_file: | ||
module = wasmtime.Module.deserialize(engine, cache_file.read()) | ||
except: | ||
print("Preparing to run {}. This might take a while...".format(argv[0]), file=sys.stderr) | ||
module = wasmtime.Module(engine, module_binary) | ||
with cache_filename.open("wb") as cache_file: | ||
cache_file.write(module.serialize()) | ||
with digest_filename.open("wb") as digest_file: | ||
digest_file.write(module_digest) | ||
|
||
store = wasmtime.Store(engine) | ||
linker = wasmtime.Linker(store) | ||
wasi = linker.define_wasi(wasmtime.WasiInstance(store, | ||
"wasi_snapshot_preview1", wasi_cfg)) | ||
app = linker.instantiate(module) | ||
try: | ||
app.exports["_start"]() | ||
return 0 | ||
except wasmtime.ExitTrap as trap: | ||
return trap.code | ||
|
||
|
||
def run_prjoxide(argv): | ||
return _run_wasm_app("prjoxide.wasm", ["yowasp-prjoxide", *argv]) | ||
|
||
|
||
def _run_prjoxide_argv(): | ||
sys.exit(run_prjoxide(sys.argv[1:])) | ||
|
||
|
||
def run_nextpnr_nexus(argv): | ||
return _run_wasm_app("nextpnr-nexus.wasm", ["yowasp-nextpnr-nexus", *argv]) | ||
|
||
|
||
def _run_nextpnr_nexus_argv(): | ||
sys.exit(run_nextpnr_nexus(sys.argv[1:])) |