@@ -25,6 +25,7 @@ import dub.project;
2525
2626import dub.compilers.buildsettings;
2727import dub.compilers.compiler;
28+ import dub.dependency;
2829import dub.generators.build;
2930import dub.generators.generator;
3031
@@ -104,7 +105,8 @@ class DubComponent : ComponentWrapper
104105 foreach (ref pkg; _dub.project.getTopologicalPackageList())
105106 {
106107 optionalifyRecipe(pkg);
107- foreach (dep; pkg.getAllDependencies().filter! (a => optionalified.canFind(a.name)))
108+ foreach (dep; pkg.getAllDependencies()
109+ .filter! (a => optionalified.canFind(a.name)))
108110 {
109111 auto d = _dub.project.getDependency(dep.name, true );
110112 if (! d)
@@ -172,7 +174,9 @@ class DubComponent : ComponentWrapper
172174
173175 bool isRunning ()
174176 {
175- return _dub ! is null && _dub.project ! is null && _dub.project.rootPackage ! is null
177+ return _dub ! is null
178+ && _dub.project ! is null
179+ && _dub.project.rootPackage ! is null
176180 && _dubRunning;
177181 }
178182
@@ -338,9 +342,9 @@ class DubComponent : ComponentWrapper
338342 auto pkg = _dub.project.rootPackage;
339343 BuildSettings settings = pkg.getBuildSettings(_platform, _configuration);
340344 return PackageBuildSettings (settings,
341- pkg.path.toString,
342- pkg.name,
343- _dub.project.rootPackage.recipePath.toNativeString());
345+ pkg.path.toString,
346+ pkg.name,
347+ _dub.project.rootPackage.recipePath.toNativeString());
344348 }
345349
346350 // / Lists all build types defined in the package description AND the predefined ones from dub ("plain", "debug", "release", "release-debug", "release-nobounds", "unittest", "docs", "ddox", "profile", "profile-gc", "cov", "unittest-cov")
@@ -373,14 +377,15 @@ class DubComponent : ComponentWrapper
373377 }
374378
375379 // / List all possible arch types for current set compiler
376- string [] archTypes () @property
380+ string [] archTypes () const @property
377381 {
378- string [] types = [" x86_64" , " x86" ];
382+ auto types = appender! (string []);
383+ types ~= [" x86_64" , " x86" ];
379384
380385 string compilerName = _compiler.name;
381386
382- if (compilerName == " dmd" )
383- {
387+ if (compilerName == " dmd" )
388+ {
384389 // https://github.com/dlang/dub/blob/master/source/dub/compilers/dmd.d#L110
385390 version (Windows )
386391 {
@@ -398,11 +403,59 @@ class DubComponent : ComponentWrapper
398403 types ~= [" aarch64" , " powerpc64" ];
399404 }
400405
401- return types;
406+ return types.data;
407+ }
408+
409+ // / ditto
410+ ArchType[] extendedArchTypes () const @property
411+ {
412+ auto types = appender! (ArchType[]);
413+ string compilerName = _compiler.name;
414+
415+ if (compilerName == " dmd" )
416+ {
417+ types ~= [
418+ ArchType(" " , " (compiler default)" ),
419+ ArchType(" x86_64" ),
420+ ArchType(" x86" )
421+ ];
422+ // https://github.com/dlang/dub/blob/master/source/dub/compilers/dmd.d#L110
423+ version (Windows )
424+ {
425+ types ~= [ArchType(" x86_omf" ), ArchType(" x86_mscoff" )];
426+ }
427+ }
428+ else if (compilerName == " gdc" )
429+ {
430+ // https://github.com/dlang/dub/blob/master/source/dub/compilers/gdc.d#L69
431+ types ~= [
432+ ArchType(" " , " (compiler default)" ),
433+ ArchType(" x86_64" , " 64-bit (current platform)" ),
434+ ArchType(" x86" , " 32-bit (current platform)" ),
435+ ArchType(" arm" ),
436+ ArchType(" arm_thumb" )
437+ ];
438+ }
439+ else if (compilerName == " ldc" )
440+ {
441+ types ~= [
442+ ArchType(" " , " (compiler default)" ),
443+ ArchType(" x86_64" ),
444+ ArchType(" x86" )
445+ ];
446+ // https://github.com/dlang/dub/blob/master/source/dub/compilers/ldc.d#L80
447+ types ~= [
448+ ArchType(" aarch64" ),
449+ ArchType(" powerpc64" ),
450+ ArchType(" wasm32-unknown-unknown-wasm" , " WebAssembly" )
451+ ];
452+ }
453+
454+ return types.data;
402455 }
403456
404- // / Returns the current selected arch type
405- string archType () @property
457+ // / Returns the current selected arch type, or empty string for compiler default.
458+ string archType () const @property
406459 {
407460 return _archType;
408461 }
@@ -413,19 +466,22 @@ class DubComponent : ComponentWrapper
413466 {
414467 enforce(request.type == JSONType.object && " arch-type" in request, " arch-type not in request" );
415468 auto type = request[" arch-type" ].fromJSON! string ;
416- if (archTypes.canFind(type))
469+
470+ try
417471 {
418- _archType = type;
419- return updateImportPaths (false );
472+ _platform = _compiler.determinePlatform(_settings, _compilerBinaryName, type);
420473 }
421- else
474+ catch ( Exception e)
422475 {
423476 return false ;
424477 }
478+
479+ _archType = type;
480+ return updateImportPaths (false );
425481 }
426482
427483 // / Returns the current selected build type
428- string buildType () @property
484+ string buildType () const @property
429485 {
430486 return _buildType;
431487 }
@@ -454,7 +510,11 @@ class DubComponent : ComponentWrapper
454510 }
455511
456512 // / Selects a new compiler for building
457- // / Returns: `false` if the compiler does not exist
513+ // / Returns: `false` if the compiler does not exist or some setting is
514+ // / invalid.
515+ // /
516+ // / If the current architecture does not exist with this compiler it will be
517+ // / reset to the compiler default. (empty string)
458518 bool setCompiler (string compiler)
459519 {
460520 try
@@ -466,8 +526,23 @@ class DubComponent : ComponentWrapper
466526 {
467527 return false ;
468528 }
469- _platform = _compiler.determinePlatform(_settings, _compilerBinaryName, _archType);
470- _settingsTemplate.getPlatformSettings(_settings, _platform, _dub.project.rootPackage.path);
529+
530+ try
531+ {
532+ _platform = _compiler.determinePlatform(_settings, _compilerBinaryName, _archType);
533+ }
534+ catch (UnsupportedArchitectureException e)
535+ {
536+ if (_archType.length)
537+ {
538+ _archType = " " ;
539+ return setCompiler (compiler);
540+ }
541+ return false ;
542+ }
543+
544+ _settingsTemplate.getPlatformSettings(_settings, _platform,
545+ _dub.project.rootPackage.path);
471546 return _compiler ! is null ;
472547 }
473548
@@ -589,7 +664,7 @@ class DubComponent : ComponentWrapper
589664 // / Returns: `[pos, pos]` if not found, otherwise range in bytes which might
590665 // / not contain the position at all.
591666 int [2 ] resolveDiagnosticRange (scope const (char )[] code, int position,
592- scope const (char )[] diagnostic)
667+ scope const (char )[] diagnostic)
593668 {
594669 import dparse.lexer : getTokensForParser, LexerConfig;
595670 import dparse.parser : parseModule;
@@ -608,7 +683,7 @@ private:
608683 Dub _dub;
609684 bool _dubRunning = false ;
610685 string _configuration;
611- string _archType = " x86_64 " ;
686+ string _archType = " " ;
612687 string _buildType = " debug" ;
613688 string _compilerBinaryName;
614689 Compiler _compiler;
@@ -802,3 +877,12 @@ string[] listDependencies(scope const Package pkg)
802877 dependencies ~= dep.name;
803878 return dependencies;
804879}
880+
881+ // /
882+ struct ArchType
883+ {
884+ // / Value to pass into other calls
885+ string value;
886+ // / UI label override or null if none
887+ string label;
888+ }
0 commit comments