~patrickb/Devel-ExecRunnerGenerator

83d2a166b551506d08a8adde3f9dceed616214cb — Patrick Böker 7 months ago 4d5f769
Build both a dynamic and a static linked CRT version

The dynamic version is a loooooot smaller (~16kb), but I think will only
work on Windows 10+ which has the UCRT installed by default. The static
version should work on older Windowses as well but is 150kb in size.
5 files changed, 21 insertions(+), 15 deletions(-)

M .gitignore
M Akefile
M META6.json
M lib/Devel/ExecRunnerGenerator.rakumod
M xt/lib/test-util.rakumod
M .gitignore => .gitignore +2 -1
@@ 5,7 5,8 @@
.precomp/
/runner-src/gen/
/runner-src/linux-x86_64
/runner-src/windows-x86_64.exe
/runner-src/windows-x86_64-static-crt.exe
/runner-src/windows-x86_64-dynamic-crt.exe
/resources/
/xt/gen/
xt/misc/echo-args

M Akefile => Akefile +14 -11
@@ 17,22 17,25 @@ task 'test' => <deploy-runner test-setup>, {
my $src-dir = $repo-dir.add: "runner-src";
my $size_file = $src-dir.add('gen/exec_size.h');
my @sources = ('whereami.c', 'runner.c').map: { $src-dir.add($_).absolute };
my $runner-win-static = "windows-x86_64-static-crt.exe";
my $runner-win-dynamic = "windows-x86_64-dynamic-crt.exe";
my $runner-linux = "linux-x86_64";
task 'runner', {
    if $*DISTRO.is-win {
        runner-win;
        runner-win($runner-win-static, ());
        runner-win($runner-win-dynamic, ('/MD',));
    }
    else {
        runner-linux;
    }
}

my $runner-win = "windows-x86_64.exe";
sub runner-win() {
    my $exec-file = $src-dir.add($runner-win);
sub runner-win($name, @options) {
    my $exec-file = $src-dir.add($name);

    sub build($len) {
        $size_file.spurt: "const unsigned long EXEC_LEN = $len;\n";
        compile($exec-file, @sources, ($src-dir.absolute,));
        compile($exec-file, @sources, ($src-dir.absolute,), extra-args => @options);
    }

    build("0");


@@ 48,7 51,6 @@ sub runner-win() {
    }
}

my $runner-linux = "linux-x86_64";
sub runner-linux() {
    my $exec-file = $src-dir.add($runner-linux);



@@ 72,8 74,9 @@ sub runner-linux() {

task 'deploy-runner' => 'runner', {
    mkdir 'resources' unless 'resources'.IO.e;
    my $name = $*DISTRO.is-win ?? $runner-win !! $runner-linux;
    $src-dir.add($name).copy: 'resources'.IO.add($name);

    my @names = $*DISTRO.is-win ?? ($runner-win-static, $runner-win-dynamic) !! ($runner-linux,);
    $src-dir.add($_).copy('resources'.IO.add($_)) for @names;
}

task 'test-setup', {


@@ 87,13 90,13 @@ task 'test-setup', {
    compile($exec-file, @sources, ());
}

sub compile(IO::Path:D $out, @sources, @includes is copy) {
sub compile(IO::Path:D $out, @sources, @includes is copy, :@extra-args) {
    if $*DISTRO.is-win {
        my @cl-args = < >;
        my @cl-args = </O2 /D "NDEBUG" /GL /Gy /Zc:inline /nologo>;

        @includes .= map({ |("/I", $_) });

        run 'cl', |@cl-args, '/Fe' ~ $out.absolute, |@includes, |@sources;
        run 'cl', |@cl-args, |@extra-args, '/Fe' ~ $out.absolute, |@includes, |@sources;
    }
    else {
        my @gcc-general-args = <-std=gnu99>;

M META6.json => META6.json +2 -1
@@ 16,7 16,8 @@
  },
  "resources" : [
    "linux-x86_64",
    "windows-x86_64.exe"
    "windows-x86_64-static-crt.exe",
    "windows-x86_64-dynamic-crt.exe"
  ],
  "source-url" : "",
  "tags" : [ ],

M lib/Devel/ExecRunnerGenerator.rakumod => lib/Devel/ExecRunnerGenerator.rakumod +2 -1
@@ 145,7 145,8 @@ enum ArgOp <missing plain cmd-args plat-sep abs abs-slash>;

my @templates = qw[
    linux-x86_64
    windows-x86_64.exe
    windows-x86_64-static-crt.exe
    windows-x86_64-dynamic-crt.exe
    macos-x86_64
    macos-arm64
];

M xt/lib/test-util.rakumod => xt/lib/test-util.rakumod +1 -1
@@ 7,5 7,5 @@ our $test-dir = $*PROGRAM.IO.parent;
our $gen-dir = $test-dir.add: 'gen';
mkdir $gen-dir unless $gen-dir.d;
our $echo-prog = $gen-dir.add(gen-exec-name("echo-args")).absolute;
our $native-arch = $*DISTRO.is-win ?? 'windows-x86_64.exe' !!
our $native-arch = $*DISTRO.is-win ?? 'windows-x86_64-static-crt.exe' !!
                                      'linux-x86_64';
\ No newline at end of file