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

XSim: better Windows support + add xcix IP import #1246

Merged
merged 6 commits into from
Jan 22, 2024
Merged

Conversation

oletf
Copy link
Contributor

@oletf oletf commented Nov 16, 2023

Follow-up to #1234

Context, Motivation & Description

Impact on code generation

None

Checklist

- [ ] Unit tests were added

@Readon
Copy link
Collaborator

Readon commented Nov 16, 2023

Please notice the fact that many people is using SpinalHDL on Windows without MSYS2 environment. So if it is on Windows there might be chance that MSYS2_ROOT is not there at all.

@oletf
Copy link
Contributor Author

oletf commented Nov 16, 2023

The only files I changed are related to XSim usage,
so if they currently don't use XSim for simulation they won't see any change as those file's code won't run more as they currently do.

But I admit that for any Windows user who wants to use XSim, the spinal_xsim.dll needs to be compiled, so it'll be necessary for the user to have at least some g++ or whatever toolchain which would be able to build it.

I kept using MSYS2 shell in this PR because that's what was used previously already.

I found some mingw in %VIVADO_HOME%\tps\mingw which has some g++ but I haven't checked its limitations.

if (isWindows) {
val msys2ShellPath =
sys.env.getOrElse("MSYS2_ROOT", "C:\\msys64") + "\\msys2_shell.cmd"
if (!new File(msys2ShellPath).exists) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this part is what I concerned.

Copy link
Contributor Author

@oletf oletf Nov 16, 2023

Choose a reason for hiding this comment

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

indeed I completely missed that this would fail on msys2 shell, thanks for spotting it!

could be changed to msys2Shell gets :

  • sh if sbt run by msys (check with sys.env.get("MSYSTEM") ?)
  • the full %MSYS2_ROOT%\\msys2_shell.cmd -defterm -here -no-start -mingw64 if ran by cmd

would that be good enough ?

pretty unsure about checking msys vs cmd with only MSYSTEM envvar,
thought about checking if sh exists, but there can be some other sh in cmd PATH

if (isWindows) {
s"sh -c \'${baseCommand}\'"
s"cmd /c $baseCommand"
Copy link
Collaborator

Choose a reason for hiding this comment

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

so do you use cmd console by default?

Copy link
Contributor Author

@oletf oletf Nov 16, 2023

Choose a reason for hiding this comment

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

yes, as mentioned in the issue a few times :
my goal was using native cmd console by default to call everything that can be :
vivado.bat, and its generated compile.bat and elaborate.bat :
so whatever if user starts sbt from cmd or from msys shell :

  • all .bat will be run by cmd
  • the g++ command to build spinal_xsim.dll is run by msysShell

@@ -111,6 +124,15 @@ class XSimBackend(config: XSimBackendConfig) extends Backend {
throw new Exception(message)
}
}
def doCmdMys2(command: String, cwd: File, message : String) = {
val cmd_msys2 = s""" $msys2Shell -defterm -here -no-start -mingw64 -c "$command" """.trim
Copy link
Collaborator

Choose a reason for hiding this comment

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

this command would not use env variable in msys if you start it through cmd shell on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, because on windows the build of spinal_xsim.dll depends only on the VIVADO_HOME env var to copy locally needed include files.

This behavior was already there before those commits, and I kept it,
as it allows to have this only step which actually doesn't depends on any PATH (cmd or msys) env var.

@Readon
Copy link
Collaborator

Readon commented Nov 16, 2023

there are normally 3 ways to use.

  1. on linux
  2. on Windows, use cmd shell
  3. on Windows, use bash of msys2

@andreasWallner
Copy link
Collaborator

there are normally 3 ways to use.

1. on linux 
2. on Windows, use cmd shell 
3. on Windows, use bash of msys2

For the windows cases: aren't they the same in the sense that g++ must always run in the msys environment (since the compiler is installed there), whereas vivado "must" always run in the cmd environment (since there are no environment settings files for bash, only settings64.bat)?

I think from that point it makes sense to call g++ via msys and vivado via cmd.

@Readon
Copy link
Collaborator

Readon commented Nov 19, 2023

there are normally 3 ways to use.

1. on linux 
2. on Windows, use cmd shell 
3. on Windows, use bash of msys2

For the windows cases: aren't they the same in the sense that g++ must always run in the msys environment (since the compiler is installed there), whereas vivado "must" always run in the cmd environment (since there are no environment settings files for bash, only settings64.bat)?

I think from that point it makes sense to call g++ via msys and vivado via cmd.

you are using method 2.

I am currently use the MSYS2 shell to start Vivado, the description in SpinalHDL/SpinalDoc-RTD#230 has been tested without cmd at all. and also with the all-in-one msys2 bundle.

A easy and unify method is prefered, because the environment of Windows norrmally a mess while the number of programs increasing.

- always use cmd to call Vivado related scripts
- always using msys's g++ to build XSIIFace dll
@andreasWallner
Copy link
Collaborator

andreasWallner commented Dec 10, 2023

@Readon anything else from your side, from my POV we can merge this (I tried it on Linux)

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

@Readon anything else from your side, from my POV we can merge this (I tried it on Linux)

I still could not run this under msys2 environment.

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

@Readon anything else from your side, from my POV we can merge this (I tried it on Linux)

I still could not run this under msys2 environment.

What I am using is the portable environment installed by MSYS2-installer. I think in MSYS2 there sould be no assumption that there would be a cmd.exe exist.

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

I also tested in the cmd console it still prompt that "Please Setup you MSYS2_ROOT Environment Variable." after I have set it by "set MSYS2_ROOT="xxxxxxx"". I have to define all environment variable in Windows System's advance settings. It might be not good if I just want to run it once, but pollute my whole environment variables.

After that, I still get " Generation of vivado script failed" error with backtrace like below.

[error]         at spinal.sim.XSimBackend.doCmd(XSimBackend.scala:125)
[error]         at spinal.sim.XSimBackend.doCmdVivado(XSimBackend.scala:141)
[error]         at spinal.sim.XSimBackend.generateScript(XSimBackend.scala:245)

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

One more thing, if the xcix is supported after this PR, how about add a minimal test on it? So that we could test this each time the CI runs.

@oletf
Copy link
Contributor Author

oletf commented Dec 11, 2023

What I am using is the portable environment installed by MSYS2-installer. I think in MSYS2 there sould be no assumption that there would be a cmd.exe exist.

For any MSYS2 installation, I assumed that we're on Windows, and that the cmd.exe native windows shell existing since the very beginnings of the OS is always present.
Also the fact that launching a .bat is not possible without a minimal cmd /c call, and that even calling a .bat from msys2 will call it through a cmd subprocess.
Or did you refer to the msys2_shell.cmd script which maybe could not have been yet added in your current msys2 version ?

"set MSYS2_ROOT="xxxxxxx""

Windows cmd syntax is very misleading on many things,
if you got spaces in the path you want to set I think it's better to do it by set "MSYS2_ROOT=xxxxxxx" (see this for details).
I always forget this it's terrible...

I have to define all environment variable in Windows System's advance settings.

Which other env var than the MSYS2_ROOT and VIVADO_HOME did you have to set to reach to the errors you got ?
Now I'm actually unsure whether java's sys.env.get gets Windows or MSYS2 env var when the java process in running as child of msys2 shell.

Writing this paragraph above I now realize that the failing at XSimBackend.scala:245 might actually be either :

  • caused by either msys2 env being different from mine
  • Vivado path resolution failing at some point
  • both

So yeah I think I cannot properly test running this by sbt from msys2, since my sbt install is in the windows side,
and msys2 is just used for g++ in my case.
I might have overlooked another thing for it to work in your specific case,
please let me know how I can try to reproduce your case on my side !

@oletf
Copy link
Contributor Author

oletf commented Dec 11, 2023

One more thing, if the xcix is supported after this PR, how about add a minimal test on it? So that we could test this each time the CI runs.

I admit I just added xcix because I needed it in my project, and just adding it to the IP import list didn't cause any problem from Vivado's pov.

Not sure about how to add a proper test for this (still lacking experience in scala testing workflow),
is there an xci test which already exists I could refer to ?

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

For any MSYS2 installation, I assumed that we're on Windows, and that the cmd.exe native windows shell existing since the very beginnings of the OS is always present. Also the fact that launching a .bat is not possible without a minimal cmd /c call, and that even calling a .bat from msys2 will call it through a cmd subprocess. Or did you refer to the msys2_shell.cmd script which maybe could not have been yet added in your current msys2 version ?

I suppose it is not a good assumption. I run the TestXSim in a standalone MSYS2 environment, there is no cmd. However, I pushed a PR on your repos, may be that helps. And it can call the compile.bat and elaborate.bat files, while you have used setEnvAndRunCmd.sh first by msys2_shell.cmd script.

Windows cmd syntax is very misleading on many things, if you got spaces in the path you want to set I think it's better to do it by set "MSYS2_ROOT=xxxxxxx" (see this for details). I always forget this it's terrible...

Yes, this might be the problem.

Which other env var than the MSYS2_ROOT and VIVADO_HOME did you have to set to reach to the errors you got ? Now I'm actually unsure whether java's sys.env.get gets Windows or MSYS2 env var when the java process in running as child of msys2 shell.

It's weird that it can get VIVADO_HOME when I define it in console but in the system. And fails to get for MSYS2_ROOT.

So yeah I think I cannot properly test running this by sbt from msys2, since my sbt install is in the windows side, and msys2 is just used for g++ in my case. I might have overlooked another thing for it to work in your specific case, please let me know how I can try to reproduce your case on my side !

If you want you can install the MSYS2-Installer, and define the environment variable in that. It can work either on current upstream code, and on the PR I have pushed on your repo.

The only problem remains is that I could not get the Windows starter, by cmd, to work now.

@Readon
Copy link
Collaborator

Readon commented Dec 11, 2023

One more thing, if the xcix is supported after this PR, how about add a minimal test on it? So that we could test this each time the CI runs.

I admit I just added xcix because I needed it in my project, and just adding it to the IP import list didn't cause any problem from Vivado's pov.

Not sure about how to add a proper test for this (still lacking experience in scala testing workflow), is there an xci test which already exists I could refer to ?

I think there is no, and the xcix is normally a commercially used one, I am not sure if you can upload it here.

make the standalone MSYS2 runs.
@Readon
Copy link
Collaborator

Readon commented Dec 31, 2023

Sorry for the late response.
I have tested the latest version on my machine. It works on MSYS2 standalone environment alright.

However, on Windows cmd & MSYS2 mixed environment it still report "UnsatisfiedLinkError", even when I defined VIVADO_HOME and add %VIVADO_HOME%\lib\win64.o to my PATH.
Almost the same as #1234 states.

@Readon Readon merged commit 26c5473 into SpinalHDL:dev Jan 22, 2024
11 checks passed
@Readon
Copy link
Collaborator

Readon commented Jan 22, 2024

Sorry for the late response. Thanks for the contribution.

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.

None yet

3 participants