Skip to content

Commit f038a9c

Browse files
committed
reformat and start windows-gui and icon
1 parent cd6e4db commit f038a9c

1 file changed

Lines changed: 125 additions & 85 deletions

File tree

opend/opend.d

Lines changed: 125 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import std.file;
2424
opend debug
2525
2626
--opend-compiler=dmd/ldmd2
27-
--opend-dev=yes
27+
--opend-dev=yes
2828
+/
2929

3030
// rumor has it arm64 for apple can be better than aarch64 but i think they the same
@@ -37,9 +37,9 @@ import std.file;
3737
// edit and test by module name instead of by file name
3838

3939
string[] testRunnerBuildArgs(string[] userArgs) {
40-
auto args = ["-g", "-oftest_runner", "-unittest", "-checkaction=context", "-version=OD_TestRunner", getBundledModulePath("odc.test_runner")];
41-
args ~= userArgs;
42-
return args;
40+
auto args = ["-g", "-oftest_runner", "-unittest", "-checkaction=context", "-version=OD_TestRunner", getBundledModulePath("odc.test_runner")];
41+
args ~= userArgs;
42+
return args;
4343
}
4444

4545
string preferredCompiler;
@@ -75,9 +75,9 @@ int main(string[] args) {
7575
case "compiler":
7676
preferredCompiler = value;
7777
break;
78-
case "dev":
79-
devCompiler = true;
80-
break;
78+
case "dev":
79+
devCompiler = true;
80+
break;
8181
default:
8282
throw new Exception("unknown opend arg: " ~ name);
8383
}
@@ -297,6 +297,21 @@ struct Commands {
297297
return 0;
298298
}
299299

300+
int processIcon(string filename) {
301+
// FIXME: error if target is not windows prolly here instead of in the compiler
302+
// gotta create a Windows resource file. this means:
303+
/+
304+
1) if it is a png, convert to ico. ico can be used directly. other formats not supported by simplifiying choice
305+
2) concat this into a .res file (can skip if unnecessary via timestamps or something but it cheap enough tbh. user can aksi use the .res externally directly if they want)
306+
2a) res file just has a header https://learn.microsoft.com/en-us/windows/win32/menurc/resourceheader
307+
2b) other resource file features maybe usable later but for now just doing the one,
308+
3) pass this file to the linker
309+
+/
310+
//
311+
argsToKeep ~= filename ~ ".res";
312+
return 0;
313+
}
314+
300315
int translateTarget(string target) {
301316
import std.string;
302317

@@ -305,8 +320,24 @@ struct Commands {
305320
string cpu;
306321
string detail;
307322

323+
string[] moreArgs;
324+
325+
string implicitTarget;
326+
version(Windows)
327+
implicitTarget = "windows";
328+
329+
string currentTargetOs() {
330+
return os.length ? os : implicitTarget;
331+
}
332+
308333
foreach(part; target.toLower.split("-")) {
309334
switch(part) {
335+
case "gui":
336+
if(currentTargetOs == "windows") {
337+
moreArgs ~= "-L/subsystem:windows";
338+
moreArgs ~= "-L/entry:mainCRTStartup";
339+
}
340+
break;
310341
case "windows":
311342
case "win64":
312343
cpu = "x86_64";
@@ -342,18 +373,18 @@ struct Commands {
342373
os = "linux";
343374
detail = "gnu";
344375
break;
345-
case "gnu.2.17":
346-
case "compat":
347-
case "compatible":
348-
// pick a glibc that is more likely to be compatible when distributed
349-
if(auto r = warnAboutXpack("xpack-zig"))
350-
return r;
376+
case "gnu.2.17":
377+
case "compat":
378+
case "compatible":
379+
// pick a glibc that is more likely to be compatible when distributed
380+
if(auto r = warnAboutXpack("xpack-zig"))
381+
return r;
351382

352383
if(cpu is null)
353384
cpu = "x86_64";
354385
os = "linux";
355386
detail = "gnu.2.17";
356-
break;
387+
break;
357388
case "arm":
358389
case "aarch64":
359390
cpu = "aarch64";
@@ -363,14 +394,14 @@ struct Commands {
363394
case "intel":
364395
cpu = "x86_64";
365396
break;
366-
case "rpi":
367-
// shortcut for raspberry pi: linux-aarch64-gnu.2.17 via zigcc
368-
if(auto r = warnAboutXpack("xpack-rpi"))
369-
return r;
370-
os = "linux";
371-
cpu = "aarch64";
372-
detail = "gnu.2.17";
373-
break;
397+
case "rpi":
398+
// shortcut for raspberry pi: linux-aarch64-gnu.2.17 via zigcc
399+
if(auto r = warnAboutXpack("xpack-rpi"))
400+
return r;
401+
os = "linux";
402+
cpu = "aarch64";
403+
detail = "gnu.2.17";
404+
break;
374405
case "wasm":
375406
case "webassembly":
376407
cpu = "wasm32";
@@ -432,6 +463,10 @@ struct Commands {
432463
addPart(detail);
433464

434465
argsToKeep ~= "--mtriple=" ~ triple;
466+
467+
if(moreArgs !is null)
468+
argsToKeep ~= moreArgs;
469+
435470
if(preferredCompiler.length == 0 || preferredCompiler == "dmd")
436471
preferredCompiler = "ldmd2";
437472

@@ -450,6 +485,8 @@ struct Commands {
450485
nextIsTarget = true;
451486
} else if(arg.startsWith("--target=")) {
452487
if(auto err = translateTarget(arg["--target=".length .. $])) return err;
488+
} else if(arg.startsWith("--icon=")) {
489+
if(auto err = processIcon(arg["--icon=".length .. $])) return err;
453490
} else if(arg.indexOf("-mtriple") != -1) {
454491
preferredCompiler = "ldmd2";
455492
} else if(arg == "-v") {
@@ -498,7 +535,7 @@ struct Commands {
498535
return 1;
499536
}
500537

501-
/// Performs a publish build then calls a user-defined deployment on the generated artifact
538+
/// Performs a publish build then calls a user-defined deployment on the generated artifact
502539
version(none)
503540
int deploy(string[] args, string[] extraBuildArgs) {
504541
// FIXME
@@ -521,36 +558,39 @@ struct Commands {
521558

522559
/// Forwards arguments directly to the OpenD dmd driver
523560
int dmd(string[] args, string[] extraBuildArgs) {
524-
if(devCompiler) {
525-
string osFolder;
526-
version(linux)
527-
osFolder = "linux";
528-
else version(Windows)
529-
osFolder = "windows";
530-
else version(OSX)
531-
osFolder = "osx";
532-
else version(FreeBSD)
533-
osFolder = "freebsd";
534-
535-
return spawnProcess([getCompilerPath("../generated/"~osFolder~"/release/64/dmd")] ~ args, null).wait.checkForCrash("dmd-dev");
536-
} else
537-
return spawnProcess([getCompilerPath("dmd")] ~ args, null).wait.checkForCrash("dmd");
561+
if(devCompiler) {
562+
string osFolder;
563+
version(linux)
564+
osFolder = "linux";
565+
else version(Windows)
566+
osFolder = "windows";
567+
else version(OSX)
568+
osFolder = "osx";
569+
else version(FreeBSD)
570+
osFolder = "freebsd";
571+
572+
return spawnProcess([getCompilerPath("../generated/"~osFolder~"/release/64/dmd")] ~ args, null).wait.checkForCrash("dmd-dev");
573+
} else {
574+
return spawnProcess([getCompilerPath("dmd")] ~ args, null).wait.checkForCrash("dmd");
575+
}
538576
}
539577

540578
/// Forwards arguments directly to the OpenD ldmd2 driver
541579
int ldmd2(string[] args, string[] extraBuildArgs) {
542-
if(devCompiler) {
543-
return spawnProcess([getCompilerPath("../ldc-build/bin/ldmd2")] ~ args, null).wait.checkForCrash("ldmd2-dev");
544-
} else
545-
return spawnProcess([getCompilerPath("ldmd2")] ~ args, null).wait.checkForCrash("ldmd2");
580+
if(devCompiler) {
581+
return spawnProcess([getCompilerPath("../ldc-build/bin/ldmd2")] ~ args, null).wait.checkForCrash("ldmd2-dev");
582+
} else {
583+
return spawnProcess([getCompilerPath("ldmd2")] ~ args, null).wait.checkForCrash("ldmd2");
584+
}
546585
}
547586

548587
/// Forwards arguments directly to the OpenD ldc2 driver
549588
int ldc2(string[] args, string[] extraBuildArgs) {
550-
if(devCompiler) {
551-
return spawnProcess([getCompilerPath("../ldc-build/bin/ldc2")] ~ args, null).wait.checkForCrash("ldc2-dev");
552-
} else
553-
return spawnProcess([getCompilerPath("ldc2")] ~ args, null).wait.checkForCrash("ldc2");
589+
if(devCompiler) {
590+
return spawnProcess([getCompilerPath("../ldc-build/bin/ldc2")] ~ args, null).wait.checkForCrash("ldc2-dev");
591+
} else {
592+
return spawnProcess([getCompilerPath("ldc2")] ~ args, null).wait.checkForCrash("ldc2");
593+
}
554594
}
555595

556596
/// Installs optional components or updates to opend
@@ -626,39 +666,39 @@ struct Commands {
626666
writeln("Installation complete, build with `opend --target=win64 <other args>`");
627667

628668
return 0;
629-
case "xpack-zig":
630-
// FIXME: need zig
631-
// can make the appropriate zigcc for it
632-
633-
version(linux) {} else {
634-
import std.stdio;
635-
stderr.writeln("Cross-compiling to linux-compat from non-linux systems not supported at this time.");
636-
return 1;
637-
}
669+
case "xpack-zig":
670+
// FIXME: need zig
671+
// can make the appropriate zigcc for it
672+
673+
version(linux) {} else {
674+
import std.stdio;
675+
stderr.writeln("Cross-compiling to linux-compat from non-linux systems not supported at this time.");
676+
return 1;
677+
}
638678

639-
auto pathToZig = args.length > 1 ? args[1] : "zig";
679+
auto pathToZig = args.length > 1 ? args[1] : "zig";
640680

641681
string ext = "";
642682
version(Windows)
643683
ext = ".bat";
644684

645-
auto dir = getXpackPath() ~ "opend-latest-xpack-zig";
646-
std.file.mkdir(dir);
685+
auto dir = getXpackPath() ~ "opend-latest-xpack-zig";
686+
std.file.mkdir(dir);
647687

648-
version(Posix) {
649-
auto filename = dir ~ "/zigcc";
650-
std.file.write(filename, "#!/bin/bash\n" ~ pathToZig ~ " cc \"$@\" -target x86_64-linux-gnu.2.17");
688+
version(Posix) {
689+
auto filename = dir ~ "/zigcc";
690+
std.file.write(filename, "#!/bin/bash\n" ~ pathToZig ~ " cc \"$@\" -target x86_64-linux-gnu.2.17");
651691

652-
std.file.setAttributes(filename, 0x1ED /* 0o755 */ );
653-
}
692+
std.file.setAttributes(filename, 0x1ED /* 0o755 */ );
693+
}
654694

655695
installConfig(`
656696
"x86_64-.*-linux-gnu.2.17":
657697
{
658698
switches = [
659-
"-defaultlib=phobos2-ldc,druntime-ldc",
660-
"-L-lunwind",
661-
"--gcc=%%ldcbinarypath%%/../xpacks/opend-latest-xpack-zig/zigcc`~ext~`",
699+
"-defaultlib=phobos2-ldc,druntime-ldc",
700+
"-L-lunwind",
701+
"--gcc=%%ldcbinarypath%%/../xpacks/opend-latest-xpack-zig/zigcc`~ext~`",
662702
];
663703
664704
// default switches appended after all explicit command-line switches
@@ -678,26 +718,26 @@ struct Commands {
678718
import std.stdio;
679719
writeln("Installation complete, build with `opend --target=linux-compat <other args>`");
680720
return 0;
681-
case "xpack-rpi":
682-
// FIXME: need zig
683-
// can make the appropriate zigcc for it
721+
case "xpack-rpi":
722+
// FIXME: need zig
723+
// can make the appropriate zigcc for it
684724

685725
string ext = "";
686726
version(Windows)
687727
ext = ".bat";
688728

689729
downloadXpack("xpack-rpi");
690730

691-
auto pathToZig = args.length > 1 ? args[1] : "zig";
731+
auto pathToZig = args.length > 1 ? args[1] : "zig";
692732

693-
version(Posix) {
694-
auto dir = getXpackPath() ~ "opend-latest-xpack-rpi";
733+
version(Posix) {
734+
auto dir = getXpackPath() ~ "opend-latest-xpack-rpi";
695735

696-
auto filename = dir ~ "/zigcc";
697-
std.file.write(filename, "#!/bin/bash\n" ~ pathToZig ~ " cc \"$@\" -target aarch64-linux-gnu.2.17");
736+
auto filename = dir ~ "/zigcc";
737+
std.file.write(filename, "#!/bin/bash\n" ~ pathToZig ~ " cc \"$@\" -target aarch64-linux-gnu.2.17");
698738

699-
std.file.setAttributes(filename, 0x1ED /* 0o755 */ );
700-
}
739+
std.file.setAttributes(filename, 0x1ED /* 0o755 */ );
740+
}
701741

702742
installConfig(`
703743
"aarch64-.*-linux-gnu.2.17":
@@ -720,7 +760,7 @@ struct Commands {
720760

721761
import std.stdio;
722762
writeln("Installation complete, build with `opend --target=rpi <other args>`");
723-
return 0;
763+
return 0;
724764
default:
725765
import std.stdio;
726766
stderr.writeln("Unknown thing");
@@ -830,7 +870,7 @@ OutputExecutable getOutputExecutable(string[] args) {
830870
void downloadXpack(string which) {
831871
import arsd.archive;
832872

833-
import std.net.curl;
873+
import std.net.curl;
834874

835875
import core.thread.fiber;
836876

@@ -899,20 +939,20 @@ void downloadXpack(string which) {
899939
import std.stdio;
900940
writeln("Downloading...");
901941

902-
auto http = HTTP(url);
903-
http.onReceive = (ubyte[] data) {
942+
auto http = HTTP(url);
943+
http.onReceive = (ubyte[] data) {
904944
availableData = data;
905945
if(!done)
906946
fiber.call();
907-
return data.length;
908-
};
909-
http.perform();
947+
return data.length;
948+
};
949+
http.perform();
910950

911951
}
912952

913953
string trimLeadingUnderscore(string s) {
914-
if(s[0] == '_')
915-
return s[1..$];
916-
return s;
954+
if(s[0] == '_')
955+
return s[1..$];
956+
return s;
917957
}
918958

0 commit comments

Comments
 (0)