Bug 12723 – Support compiling C/C++ files in D projects

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
visuald
Product
D
Version
D2
Platform
All
OS
Windows
Creation time
2014-05-09T16:46:00Z
Last change time
2015-01-01T22:19:06Z
Assigned to
nobody
Creator
turkeyman

Comments

Comment #0 by turkeyman — 2014-05-09T16:46:50Z
It would be nice if VisualD projects could support compiling C/C++ code in addition to D code when .c/.cpp files are added to the project, in just the same way that C++ projects fall back to C mode when compiling .c files. It is common that a .c file finds its way into D projects. Druntime has a .c and a .asm file. phobos compiles zlib together with the rest of the D code. The idea is not to support full blown C projects with all the bells and whistles, but to make it possible to express such a project where there is just a couple of C files along with the majority D code. It's very awkward to split these up into multiple project files in Visual Studio. I suggest: Win64 - invoke MSC, and then supply the result .obj file to DMD as it builds the D code. Win32 - invoke DMC, same story. GCC - GCC is always present alongside GDC, and most of the same build flags are supported between compilers. LDC - invoke clang? I think as a goal, it should be possible to express druntime and phobos in a visualdproj without any awkward mischief.
Comment #1 by r.sagitario — 2014-05-13T22:09:59Z
You can do this with the custom build tool, including adding dependencies and output filename to be added to the link. The commnd line can be set once for all configurations or differently for each configuration. I'm not sure explicite support for C/C++ files is worth the effort. Without implementing controls for all the compiler options, you'll have to specify most of the command line yourself anyway.
Comment #2 by turkeyman — 2014-05-17T05:25:01Z
Custom build tool is really awkward when build dependencies and linkage are all required steps. I'm not saying it's an urgent feature, but I feel it would be pretty valuable, since I don't think it's uncommon by any means, and would probably allow a lot of people a lot less friction to get their project running. Most Visual Studio users have no idea how to execute a compiler via the command line (and consequently hook it all up via a custom build tool). I mean, that kinda the point of VS integration. I think it'd only need a couple of the most important options, and for GDC/LDC builds, a lot of the options are shared (optimisation, debuginfo, linker, etc). On a separate note, I was looking at the builtin MSBuild scripts for C/C++, and it occurred to me that it might be possible to hack D support into the official vcxproj stuff. Did you ever look into that? I expect that approach would have no way to hook special code for autocomplete and stuff though right? (I have no idea about the VS extensibility API)
Comment #3 by r.sagitario — 2014-05-17T07:09:40Z
I just tried how it works with setting up projects for druntime and phobos, and adding "dmc -c -o$(IntDir)\$(InputName).obj $(InputPath)" for C files (and specifying the output path works for Win32 builds. You'll run into problems with "out of memory" when building unittests (enable single file compilation), and too much debug info, though, but the latter is an issue with OMF tool chain. Trying to get some (android-sdk) VS integration to work which uses MSBuild, I noticed, these work by switching the "Platform Toolset". This seems like an "switch everything" approach, but the Intel compiler integration seems to change/add just a few entries of the project settings. It might be possible to setup some rules for dmc, or to integrate dmd, though that would exclude VS2008 and earlier from the list of supported versions. I'm not sure stuff like dependency handling will work smoothly. Language service (including intellisense) is only slightly coupled with project managements (mostly reading compile options). That would remain the same.
Comment #4 by r.sagitario — 2014-11-07T13:52:23Z
Comment #5 by r.sagitario — 2015-01-01T22:19:06Z
released in 0.3.40.