-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Importing os module for use in macros fails when compiling for platform that doesn't support os #19414
Comments
I think this works as intended but I've also walked into wanting to run the VM for my host OS and not target so perhaps a |
Why should compile time emulate the target though? Compile time is compile time, and should use whatever the compiling machine is defined as. You could easily run into a similar issue if you're cross compiling for example, it could end up trying to import something which won't work on compile-time simply because you're targeting another platform. |
The possible issue I see is that if your VM is being ran as if a different OS specific symbols you attempt to fetch may not be available to the target, causing compilation errors. when defined(linux):
proc doThing() =
someCompileTimeProcThatOnlyWorksOnLinux()
echo "hello"
elif defined(windows):
proc doThing() =
someCompileTimeProcThatOnlyWorksOnWindows()
echo "World"
static:
doThing() Which Edit: At least in this case the solution is just to implement the vmOps in |
IMO VM-only overrides should be their own symbols and not depend on existing standard library functions. This is a pain point for JS but I don't think it'd be a huge problem for the VM given how much less commonly these functions are used. |
@beef331, this isn't exclusively an issue for the |
@metagn That's what we used to do but people found it too confusing, so we got a new policy "just make everything work at compile-time". I don't like this policy at all but I also don't want to change it yet again and break people's code. |
This is really starting to frustrate me.. I just had to go digging with |
Example
Current Output
When compiling for
--os:any
Expected Output
No error, should be able to use
walkDir
and other things from os in a macro even though the target platform doesn't support the module. The module is explicitly mentioned to work with NimScript, so using it in this way should work.Possible Solution
Maybe support
static: import os
to import it only into the static context where it could be used in macros. Or move the check to error out when procedures are actually used at runtime.The text was updated successfully, but these errors were encountered: