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

Fix questa/modelsim on Windows #882

Closed
wants to merge 2 commits into from
Closed

Conversation

themperek
Copy link
Contributor

@themperek themperek commented Mar 22, 2019

Tested on latest Questa (32 and 64) and Modelsim 12.1 (32) using conda + msys2

Will update documentation as next step.

Usage:

  • Install simulator ex. Icarus and add to PATH to the *.exe folder
  • Install Miniconda (according to your simulation version 32/64bit)
  • Start Anaconda Prompt
  • Install msys conda install -c msys2 m2-base m2-make m2w64-toolchain libpython
  • Install cocotb (for questa you use https://github.com/themperek/cocotb/tree/questa_win questa_win branch)

see also: Dockerfile.windows

Tested on latest Questa (32 and 64) and Modelsim 12.1 (32) using conda + msys2
@themperek themperek added category:OS:Windows Microsoft Windows-specific issues status:ready-for-merge this PR is ready (according to the Patch Requirements) to be merged labels Mar 22, 2019
@@ -131,7 +140,9 @@ EXTRA_LIBDIRS := -L$(MODELSIM_BIN_DIR)
OLD_PATH := $(shell echo "$(PATH)" | sed 's/(/\\(/g' | sed 's/)/\\)/g' | sed 's/ /\\ /g')

LIB_LOAD := PATH=$(MINGW_BIN_DIR):$(OLD_PATH):$(LIB_DIR)
NEW_PYTHONPATH := $(shell echo "$(PYTHONPATH)" | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\):\//\/\1\//g' -e 's/;/:/g')
NEW_PYTHONPATH:=$(shell python -c "import sys, os; print(':'.join(['/'+dir.replace(os.sep,'/').replace(':','') for dir in sys.path]))")
Copy link
Member

Choose a reason for hiding this comment

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

This could really do with a comment. I assume it's the same as all the other makefiles?

Copy link
Member

Choose a reason for hiding this comment

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

Would print(os.pathsep.join(subprocess.check_output(['cygpath', '-m', d]) for d in sys.path)) work here?

Copy link
Contributor Author

@themperek themperek Apr 19, 2019

Choose a reason for hiding this comment

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

Can do but in practice it will be something like this:

python -c "import sys, os, subprocess; print(os.pathsep.join(str(subprocess.check_output(['cygpath', '-m', d]))[2:-3] for d in sys.path if d != '' ))"

Is that better?

@imphil imphil added status:changes-requested changes are requested to the code and removed status:ready-for-merge this PR is ready (according to the Patch Requirements) to be merged labels Mar 25, 2019
@imphil
Copy link
Member

imphil commented Mar 25, 2019

Thanks @themperek for working on our Windows builds.

However, I'm not a fan of those changes, it's effectively piling workarounds on top of each other, one simulator at a time. What we need to have is a function that knows how to format a PATH-like list of directories and a file path according to the environment rules. Since especially msys has rules that differ depending on how you call it (cygwin paths or native windows paths) it doesn't make sense to spread this ugly and error-prone environment logic spread all Makefiles.

@themperek
Copy link
Contributor Author

I would rather work on getting ride of Makefiles ....

@themperek
Copy link
Contributor Author

themperek commented Mar 26, 2019

@imphil Where those functions should be located? In makefile? In cocotb? Can try to write them with sed (like it was before). Not sure if this can be done in a "nice" way.

Ex. Modelsim/Questa seems to accept only path in a form C:/a/b in the command file (nor C:\a\b, nor /c/a/b seems to work for me).

The same situation is already here: https://github.com/potentialventures/cocotb/blob/master/cocotb/share/makefiles/simulators/Makefile.icarus

@eric-wieser
Copy link
Member

Modelsim/Questa seems to accept only path in a form C:/a/b in the command file

It seems very unlikely to me that these care about the PYTHONPATH variable - that should be touched only by the python interpreter, which is independent of the simulator.

@themperek
Copy link
Contributor Author

themperek commented Mar 26, 2019

For PYTHONPATH it seems to accept only /c/a/b format for me (Win 10).
In any case PYTHONPATH has to be taken from python sys.path for me to work (Win 10).

@gretzteam
Copy link

gretzteam commented May 28, 2019

Hi,
I tried this (which is VERY nice as the entire thing is part of the conda installation instead of having to deal with msys2 install and all the other stuff). It actually works fine for the examples/adder test, but it fails as soon as I try to import numpy inside the test. The error is similar to what is discussed here, I pasted it below:
numpy/numpy#12957

I tried with miniconda, then anaconda, removed/updated numpy etc...no luck.

Since the change here was about the path, I wonder if you see the same issue on your end and maybe it's not a local issue on my side? Just importing numpy causes the crash.

Thanks!


> #      0.00ns CRITICAL Failed to import module test_mac: DLL load failed: The specified module could not be found.
> #
> #      0.00ns INFO     MODULE variable was "test_mac"
> #
> #      0.00ns INFO     Traceback:
> #
> #      0.00ns INFO     Traceback (most recent call last):
> #
> #                        File "C:\ProgramData\Anaconda3\lib\site-packages\cocotb\regression.py", line 133, in initialise
> #
> #                          module = _my_import(module_name)
> #
> #                        File "C:\ProgramData\Anaconda3\lib\site-packages\cocotb\regression.py", line 63, in _my_import
> #
> #                          mod = __import__(name)
> #
> #                        File "C:\cocotb\designs\MACtest\tests\test_mac.py", line 8, in <module>
> #
> #                          import numpy as np
> #
> #                        File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
> #
> #                          from . import _distributor_init
> #
> #                        File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
> #
> #                          from . import _mklinit
> #
> #                      ImportError: DLL load failed: The specified module could not be found.

@themperek
Copy link
Contributor Author

It looks like missing LD_LIBRARY_PATH to extra dll (in this case numpy). Will try to have a look.

@gretzteam
Copy link

Hi,
Got it to work! I don't think there is any problem with the Makefiles.
Had to install numpy using pip instead of conda!? I uninstalled it and simply re-installed using pip. Everything is fine now...
Maybe 'conda' puts some dll or library somewhere that isn't part of the MANY variations of /ProgramData/Miniconda3/xxx that are already in the path, but I don't know where...

@themperek
Copy link
Contributor Author

@imphil I know this is not very nice but I have no better idea with makefiles and without this on Windows is hard to make this working.

@elgorwi
Copy link
Contributor

elgorwi commented Jul 18, 2019

I'd like to see this PR merged in some way or another.
If we're prepared to use cygpath, it will open up some possibilities to clean up the rather fragile situation of VERILOG_SOURCES/VHDL_SOURCES in the user makefiles with the $(WPWD) variable. We could then simply use $(PWD) for both nix and windows. This will require some work on the other simulator specific makefiles though.
Also note that cygpath -p -u could be used to convert the PYTHONPATH variable. The -p option allows cygpath to convert a path list. Unfortunately this will only work with sane paths (no spaces or special chars)

@themperek
Copy link
Contributor Author

@elgorwi You can try this: https://github.com/themperek/cocotb-test/ (still experimental but should make windows much nicer experience long run)

@elgorwi
Copy link
Contributor

elgorwi commented Jul 18, 2019

@themperek that looks really cool! I'll have to try it out when I get some spare time. Thanks

@themperek
Copy link
Contributor Author

Close in favor of #1099

@themperek themperek closed this Aug 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:OS:Windows Microsoft Windows-specific issues status:changes-requested changes are requested to the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants