Skip to content

Commit 61de634

Browse files
committed
add "import C defines" to msbuild options
enable the import C preprocessing
1 parent 9fee591 commit 61de634

14 files changed

Lines changed: 149 additions & 18 deletions

File tree

CHANGES

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,11 +1449,12 @@ Version history
14491449
2025-07-15 version 1.4.1
14501450
* dmdserver: do not display invalid struct size and alignment in tool tip
14511451

1452-
2025-07-15 version 1.4.2
1452+
2025-09-03 version 1.4.2-beta1
14531453
* dmdserver: fixed error "module specified twice on command line" for same module name in
14541454
different packages
1455+
* dmdserver: added support for importing C files
14551456
* added command "Reset Language Server" to extension menu
14561457
* issue #313: installer now checks whether VS and the C++ development workloads are installed
14571458
and provides some assistance in installing them
14581459
* dbuild: add file imported from C to the dependencies for rebuilding
1459-
* dbuild: add option to set C include search path
1460+
* dbuild: add option to set C include search path and C #defines

msbuild/dbuild/CompileD.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public CompileD()
4242
public string[] StringImportPaths { get { return opts.StringImportPaths; } set { opts.StringImportPaths = value; } }
4343
public string[] VersionIdentifiers { get { return opts.VersionIdentifiers; } set { opts.VersionIdentifiers = value; } }
4444
public string[] DebugIdentifiers { get { return opts.DebugIdentifiers; } set { opts.DebugIdentifiers = value; } }
45-
public string ObjectFileName { get { return opts.ObjectFileName; } set { opts.ObjectFileName = value; } }
45+
public string[] ImportCDefines { get { return opts.ImportCDefines; } set { opts.ImportCDefines = value; } }
46+
public string ObjectFileName { get { return opts.ObjectFileName; } set { opts.ObjectFileName = value; } }
4647
public bool PreserveSourcePath { get { return opts.PreserveSourcePath; } set { opts.PreserveSourcePath = value; } }
4748
public string CRuntimeLibrary { get { return opts.CRuntimeLibrary; } set { opts.CRuntimeLibrary = value; } }
4849
public bool Profile { get { return opts.Profile; } set { opts.Profile = value; } }

msbuild/dbuild/CompileDOpt.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ public CompileDOptions(IToolSwitchProvider provider)
5959
this.switchOrderList.Add("CodeGeneration");
6060

6161
this.switchOrderList.Add("ImportPaths");
62-
this.switchOrderList.Add("ImportCPaths");
6362
this.switchOrderList.Add("StringImportPaths");
6463
this.switchOrderList.Add("VersionIdentifiers");
6564
this.switchOrderList.Add("DebugIdentifiers");
65+
this.switchOrderList.Add("ImportCPaths");
66+
this.switchOrderList.Add("ImportCDefines");
6667
this.switchOrderList.Add("ObjectFileName");
6768
this.switchOrderList.Add("PreserveSourcePath");
6869
this.switchOrderList.Add("CRuntimeLibrary");
@@ -206,6 +207,16 @@ public string[] ImportCPaths
206207
}
207208
}
208209

210+
public string[] ImportCDefines
211+
{
212+
get { return GetStringArray("ImportCDefines"); }
213+
set
214+
{
215+
SetStringArray("ImportCDefines", false, "Import C Preprocessor Defines",
216+
"#defines for imported C files. (-P-D[ident[=val]]).", "-P-D", value);
217+
}
218+
}
219+
209220
public string[] VersionIdentifiers
210221
{
211222
get { return GetStringArray("VersionIdentifiers"); }

msbuild/dcompile.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202

203203
ImportPaths="%(DCompile.ImportPaths)"
204204
ImportCPaths="%(DCompile.ImportCPaths)"
205+
ImportCDefines="%(DCompile.ImportCDefines)"
205206
StringImportPaths="%(DCompile.StringImportPaths)"
206207
VersionIdentifiers="%(DCompile.VersionIdentifiers)"
207208
DebugIdentifiers="%(DCompile.DebugIdentifiers)"

msbuild/dcompile_defaults.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@
107107
<VersionIdentifiers></VersionIdentifiers>
108108
<DebugIdentifiers></DebugIdentifiers>
109109
<ImportPaths></ImportPaths>
110-
<ImportCPaths></ImportCPaths>
111110
<StringImportPaths></StringImportPaths>
111+
<ImportCPaths></ImportCPaths>
112+
<ImportCDefines></ImportCDefines>
112113
<AdditionalOptions></AdditionalOptions>
113114
<CompilationModel>Project</CompilationModel>
114115
<CRuntimeLibrary>MultiThreaded</CRuntimeLibrary>

msbuild/dmd.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
Description="compile in debug code identified by ident/&lt;= level." Switch="-debug=" />
5151
<StringListProperty Name="ImportCPaths" Category="General" DisplayName="Include C Paths" Description="where to look for C includes in imported C files."
5252
Subtype="folder" Switch="-P-I" />
53+
<StringListProperty Name="ImportCDefines" Category="General" DisplayName="Import C Preprocessor Defines"
54+
Description="#defines for imported C files." Switch="-P-D" />
5355

5456
<EnumProperty Name="CompilationModel" Category="General" DisplayName="Compilation Model" IncludeInCommandLine="false"
5557
Description="Compilation model if object file name is empty: project, package or single.">

msbuild/ldc.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
Description="compile in debug code identified by ident/&lt;= level." Switch="-debug=" />
5151
<StringListProperty Name="ImportCPaths" Category="General" DisplayName="Include C Paths" Description="where to look for C includes in imported C files."
5252
Subtype="folder" Switch="-P-I" />
53+
<StringListProperty Name="ImportCDefines" Category="General" DisplayName="Import C Preprocessor Defines"
54+
Description="#defines for imported C files." Switch="-P-D" />
5355

5456
<EnumProperty Name="CompilationModel" Category="General" DisplayName="Compilation Model" IncludeInCommandLine="false"
5557
Description="Compilation model if object file name is empty: project, package or single.">

nsis/visuald.nsi

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@
230230
Var VSVersion
231231
Var VCVersion
232232
Var VCPath
233-
Var MSBuildOnly
234233

235234
;--------------------------------
236235
;Interface Settings
@@ -1425,11 +1424,6 @@ FunctionEnd
14251424
;--------------------------------
14261425
Function .onInit
14271426

1428-
${GetOptions} $CMDLINE "/msbuild" $MSBuildOnly
1429-
IfErrors NotMSBuild
1430-
StrCpy $MSBuildOnly "yes"
1431-
NotMSBuild:
1432-
14331427
${MementoSectionRestore}
14341428

14351429
!ifdef VS_NET

stdext/stdext.visualdproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@
916916
<useArrayBounds>0</useArrayBounds>
917917
<boundscheck>0</boundscheck>
918918
<useSwitchError>0</useSwitchError>
919-
<useUnitTests>0</useUnitTests>
919+
<useUnitTests>1</useUnitTests>
920920
<useInline>0</useInline>
921921
<release>1</release>
922922
<preservePaths>0</preservePaths>

stdext/string.d

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,72 @@ string[] tokenizeArgs(string text, bool semi_is_seperator = true, bool space_is_
6565
return args;
6666
}
6767

68+
// Microsoft like quoting
69+
string[] splitCmdLine(string cmdline, bool removeSlashes = true)
70+
{
71+
string[] args;
72+
for (size_t p = 0; p < cmdline.length; p++)
73+
{
74+
if (cmdline[p] == ' ' || cmdline[p] == '\t')
75+
continue;
76+
size_t q = p;
77+
size_t quotes = 0;
78+
while (q < cmdline.length)
79+
{
80+
auto c = cmdline[q];
81+
if ((quotes & 1) == 0 && (c == ' ' || c == '\t'))
82+
break;
83+
q++;
84+
if (c == '\\')
85+
{
86+
size_t slash = q - 1;
87+
while (q < cmdline.length && cmdline[q] == '\\')
88+
q++;
89+
if (q < cmdline.length && cmdline[q] == '"')
90+
{
91+
size_t slashes = q - slash;
92+
if (removeSlashes)
93+
{
94+
// strip half the slashes, if odd, escape the '"'
95+
size_t nq = slash + (slashes >> 1);
96+
cmdline = cmdline[0..nq] ~ cmdline[q .. $];
97+
q = nq + 1;
98+
}
99+
if (slashes & 1)
100+
q++;
101+
else
102+
quotes++;
103+
}
104+
}
105+
else if (c == '"')
106+
{
107+
quotes++;
108+
}
109+
}
110+
auto arg = cmdline[p..q];
111+
if (quotes == 2 && arg[0] == '"' && arg[$-1] == '"')
112+
arg = arg[1..$-1];
113+
args ~= arg;
114+
p = q;
115+
}
116+
return args;
117+
}
118+
119+
unittest
120+
{
121+
string[] args = splitCmdLine("a b c");
122+
assert(args[0] == "a" && args[1] == "b" && args[2] == "c");
123+
124+
args = splitCmdLine(q"(a "b b" c)");
125+
assert(args[0] == "a" && args[1] == "b b" && args[2] == "c");
126+
127+
args = splitCmdLine(q"(a "b\ b\\" c)");
128+
assert(args[0] == "a" && args[1] == q"(b\ b\)" && args[2] == "c");
129+
130+
args = splitCmdLine(q"(a "b\" b\\" c)");
131+
assert(args[0] == "a" && args[1] == q"(b" b\)" && args[2] == "c");
132+
}
133+
68134
string unquoteArgument(string arg)
69135
{
70136
if(arg.length <= 0 || arg[0] != '\"')
@@ -76,6 +142,14 @@ string unquoteArgument(string arg)
76142
return arg[1..$-1];
77143
}
78144
145+
string quoteArgument(string arg)
146+
{
147+
if(arg.indexOf(' ') < 0 && arg.indexOf('\t') < 0)
148+
return arg;
149+
150+
return "\"" ~ arg ~ "\"";
151+
}
152+
79153
string replaceCrLfSemi(string s)
80154
{
81155
return replace(replace(s, "\n", ";"), "\r", "");

0 commit comments

Comments
 (0)