Skip to content

Conversation

@pepijndevos
Copy link
Contributor

This fixes #373 supposedly, let's see what CI has to say about it. It's a bit sketchy with manually compiling native build dependencies.

Here is what Claude had to say about it:

This commit enables XSPICE extensions in the libngspice recipe for WebAssembly, addressing several build challenges:

  1. Enable --enable-xspice configure flag
  2. Build cmpp (code model preprocessor) natively first, then use it during the WebAssembly build to avoid cross-compilation issues
  3. Add patch to fix verilog install-exec-hook which assumes shared libraries are built (not the case in WebAssembly builds)

The build process now:

  • Builds cmpp natively in build-native/ directory
  • Configures and builds WebAssembly version in release-lib/ directory
  • Replaces WebAssembly cmpp with native version before continuing build
  • Patches verilog Makefile to handle absence of shared libraries

Tested and verified to build successfully with XSPICE enabled.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Package Build Results

Total packages built: 50
Total build time: 0:14:31

Package Build Times (click to expand)
Package Build Time
libngspice 8m 49s
libhdf5 7m 45s
libopenssl 4m 40s
numpy 4m 14s
matplotlib 2m 59s
sqlite3 2m 1s
libwebp 1m 55s
Pillow 1m 47s
libtiff 1m 32s
liblzma 1m 5s
h5py 1m 3s
contourpy 50s
test 26s
kiwisolver 24s
libzlib 20s
regex 13s
pyyaml 11s
cffi 9s
ssl 8s
hashlib 7s
libyaml 6s
pydoc_data 5s
lzma 5s
pydecimal 5s
MarkupSafe 5s
atomicwrites 3s
cycler 2s
packaging 2s
pycparser 2s
inspice 1s
more-itertools 1s
diskcache 1s
exceptiongroup 1s
python-dateutil 1s
attrs 1s
pytest-asyncio 1s
Jinja2 1s
fonttools 1s
ply 1s
setuptools 1s
pyparsing 1s
py 1s
pluggy 1s
pytz 1s
pytest 1s
iniconfig 0s
pkgconfig 0s
micropip 0s
tblib 0s
six 0s

Longest build: libngspice (8m 49s)
Packages built in more than 10 minutes: 0

@pepijndevos
Copy link
Contributor Author

yea no I don't think Claude has any clue what it's doing and xspice adds a ton of extra complications of loading shared modules. It's kinda gone into clueless panic mode which rarely ends well, just changing random things, giving up, and claiming it works.

This is definitely going to be more difficult than just enabling the option and fixing a few issues, or telling Claude to do so.

@pepijndevos
Copy link
Contributor Author

Well after a lot of babysitting both Claude and my actual baby, I managed to coerce it towards the right solution. I wouldn't say it was efficient, but I could do it from my phone while also taking care of the actual baby.

The main things it struggled with are failing to build matplotlib to actually run the tests, and the CI error was from unpickeling exceptions that don't exist in the host, masking the actual error and sending it on a wild goose chase. Once I got it to test pyodide on node manually and add some error logging we started a very slow human+ci+ai in the loop debugging process.

- Enable XSPICE in libngspice build with --enable-xspice
- Build cmpp natively for code model generation (wasm can't execute)
- Package XSPICE code model libraries (*.cm files) to /usr/lib/ngspice/
- Add XSPICE mixed-signal test with ADC bridge
- Use NgSpiceShared.new_instance() to avoid cffi duplicate declarations
- Fix verilog install hook to prevent build errors
@pepijndevos pepijndevos force-pushed the claude/libngspice-xspice-build-01DcMmL97gGrf9Cfr4s9T24p branch from 4434bab to 347a03b Compare November 20, 2025 10:01
Copy link
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

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

Thanks. I literally have zero knowledge about this library and the package, so I will believe you ¯_(ツ)_/¯

I left some minor comments, otherwise it looks good to me overall.

ngspice = NgSpiceShared.new_instance()

# Load XSPICE code model
ngspice.exec_command("codemodel /usr/lib/ngspice/digital.cm")
Copy link
Member

Choose a reason for hiding this comment

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

In some environments (e.g. pyodide venv) we don't install shared libraries to /usr/lib as it actually points the native directory, but I guess it should be okay for unit test.

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.

Compile ngspice with --enable-xspice

3 participants