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
ImportC preprocess Win32 C programs with sppn.exe #14090
Conversation
Thanks for your pull request, @WalterBright! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14090" |
As expected, Win32 tests are failing because sppn.exe isn't on the test machine. |
Do we really care about this? OMF will soon be deprecated. |
Even while it's deprecated, it still needs to work. |
Why? What does this buy us?
is as assertion. What it the reasoning/motivation behind it? |
"ImportC doesn't work for Win32 OMF, though dmd does" is not a good look for us. Especially since it's just few lines of code to support it. |
Neither of those thing are completely true though. Automatic preprocessing of includes is not the entirety of importC, and DMD does not work correctly for OMF is the entire reason it will be deprecated. |
Yes, it does. The fact that vibe.d was using the wrong import libs is not persuasive. (The import libs needed to be run through It's less work to support OMF with sppn.exe than it is to constantly have to explain why not. |
dm857.zip is installed to build druntime and phobos, but PATH doesn't include it (see lines 78+ in the log). The MS linker is not required it to be found via PATH, so I think |
The test suite finds |
That's because |
optlink comes wih dmd, and is found without PATH due to sc.ini. Adding sppn to dmd is probably not a good idea as it needs dmc's include files, too. |
I need your expertise to make this work.
My reading of dmd's call to optlink is it calls spawnlp which looks along the PATH. sc.ini can override that, of course, by setting LINKCMD.
For none of the test suite does it need dmc's include files. If the user has C code and uses dmc, he likely has dmc installed with its include files. If the user writes new C code, and imports core.stdc.stdio, he might not need the dmc header files :-) Besides, sppn.exe is 200K in size. Not very big, not a burden to the install. And it eliminates a point of irritation for the user. Lastly, in order to run the dmd test suite, it needs sppn.exe on the test machine. |
@rainers I'm not sure what druntime and phobos need from dmc to compile. It does need snn.lib, but that is available separately from dmc. |
I was afraid I could be dragged in here ;-) I can have a look...
And it always does with:
druntime compiles errno.c, and phobos compiles zlib. |
I'm already using your's and Benjamin's code to intercept stdout. You know the VC ecosystem infinitely better than I do, so I sure appreciate your help!
I hate adding another variable, but I suppose SPPCMD grumble grumble
You're right, I forgot. We could figure out a way to avoid compiling errno.c, but zlib is another matter. |
errno.c is almost redundant, but it's safer to keep it around for platforms where we haven't introduced D bindings/wrappers for. |
See #14092 |
We should have this while dmd has any hint of OMF support but we should and can move away from OMF. In my experience helping people new to D it's solely been a source of confusion (and isn't actually in use in many 32 bit builds anyway since dub doesn't use it). |
7245d71
to
655cf07
Compare
I just noticed that src/dmd/link.d | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/dmd/link.d b/src/dmd/link.d
index 20a7251f6..a5b1ae6d4 100644
--- a/src/dmd/link.d
+++ b/src/dmd/link.d
@@ -1063,7 +1063,8 @@ public int runPreprocessor(const(char)[] cpp, const(char)[] filename, const(char
/* Run command, intercept stdout, remove first line that CL insists on emitting
*/
OutBuffer buf;
- buf.printf("cl /P /nologo %.*s /Fi%.*s",
+ buf.writestring(cpp);
+ buf.printf(" /nologo %.*s /Fi%.*s",
cast(int)filename.length, filename.ptr, cast(int)output.length, output.ptr);
ubyte[2048] buffer = void;
@@ -1116,11 +1117,12 @@ public int runPreprocessor(const(char)[] cpp, const(char)[] filename, const(char
}
else if (target.objectFormat() == Target.ObjectFormat.omf)
{
- argv.push("sppn".xarraydup.ptr); // Digital Mars C preprocessor
+ auto szCmd = cpp.xarraydup.ptr;
+ argv.push(szCmd); // Digital Mars C preprocessor
argv.push(filename.xarraydup.ptr); // and the input file
argv.push(null); // argv[] always ends with a null
// spawnlp returns intptr_t in some systems, not int
- return spawnvp(_P_WAIT, "sppn".ptr, argv.tdata());
+ return spawnvp(_P_WAIT, szCmd, argv.tdata());
}
else
{ Adding "/P" to the command in |
714c62f
to
87e6fd0
Compare
Thanks, trying your changes now. I left the |
It's running sppn now! Yay! Thanks, @rainers |
The OMF tests fail with:
The \t is being replaced by a tab. But who is doing it? |
72660e1
to
861b30a
Compare
I found the problem. Microsoft's preprocessor outputs a preprocessed line directive as:
whereas sppn.exe emits:
I'll see about modifying lexer.d to accommodate this. |
62c439f
to
407a4d6
Compare
Wound up modifying sppn.exe instead. Also, sppn.exe does not support U character literals, so moved that test into a .i file. |
407a4d6
to
94721ef
Compare
94721ef
to
6bc07e8
Compare
working now! |
Agreed, but it is now passed twice as |
assert(ext); | ||
const ifilename = FileName.addExt(name[0 .. name.length - (ext.length + 1)], i_ext); | ||
const command = cppCommand(); | ||
auto status = runPreprocessor(command, csrcfile.toString(), ifilename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preprocess
now has the same code for Posix and Windows. Folding that into unconditional code and keeping OS differences to runPreprocessor
seems natural.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea, but I'd prefer to do that as a refactoring.
Judging from the Codecov warnings, it's not being tested though. Edit: looks like coverage is 64-bit only |
Code coverage testing is not done for Win32. |
To get sppn.exe: http://ftp.digitalmars.com/sppn.zip for the Windows test setups.