diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 5a23cf99..bac2ac0b 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -22,22 +22,43 @@ jobs: shell: bash - run: source activate && mingw32-make shell: bash - - run: mkdir jou - - name: Copy files + # We don't need to copy all of mingw64. We only need the linker. + # The less we copy, the smaller the resulting zip becomes. + - name: Copy some parts of mingw64 to jou/mingw64 + shell: bash + run: | + # .a files compress well, so copy them all. + # CRT (C RunTime) files are needed because the linker implicitly adds them to every executable. + # version_info.txt is only for curious humans. + for file in $(find mingw64 -name '*.a') $(find mingw64 -name 'crt*.o') mingw64/version_info.txt; do + mkdir -vp jou/$(dirname $file) + cp -v $file jou/$file + done + + # executables without their DLLs (added later) + # + # clang is needed only to run the linker. It would be possible to invoke ld.exe + # directly, but the command-line it wants is a bit complicated and it's just + # easier to let clang figure it out. + mkdir -v jou/mingw64/bin + cp -v mingw64/bin/clang.exe mingw64/bin/ld.exe jou/mingw64/bin/ + - name: Copy more files to jou/ # Please keep this list of files in sync with update.ps1 - run: cp -rv stdlib doc examples mingw64 LICENSE jou.exe update.ps1 jou + run: cp -rv stdlib doc examples LICENSE jou.exe update.ps1 jou shell: bash - - name: Copy DLL files + - name: Copy missing DLL files to jou/ shell: bash run: | - ready=no - while [ $ready == no ]; do - ready=yes - for file in $(objdump -p jou/jou.exe jou/*.dll | grep 'DLL Name:' | cut -d: -f2 | grep -vEi 'kernel32.dll|msvcrt.dll|advapi32.dll|ole32.dll|shell32.dll'); do - if ! [ -f jou/$file ]; then - cp -v mingw64/bin/$file jou/ - ready=no - fi + for bindir in jou jou/mingw64/bin; do + ready=no + while [ $ready == no ]; do + ready=yes + for file in $(mingw64/bin/objdump -p $bindir/*.exe $bindir/*.dll | grep 'DLL Name:' | cut -d: -f2 | sort -u); do + if [ -f mingw64/bin/$file ] && ! [ -f $bindir/$file ]; then + cp -v mingw64/bin/$file $bindir/ + ready=no + fi + done done done - name: Convert text files to Windows-style CRLF line endings diff --git a/src/run.c b/src/run.c index 1f201f93..e34c84c9 100644 --- a/src/run.c +++ b/src/run.c @@ -62,16 +62,9 @@ static void run_linker(const char *objpath, const char *exepath, const CommandLi char *command; #ifdef _WIN32 - char *gcc = malloc_sprintf("%s\\mingw64\\bin\\gcc.exe", instdir); - if (stat(gcc, &(struct stat){0}) != -1) { - // The Windows builds come with the GNU linker. - // Windows quoting is weird, in this command it strips the outermost quotes. - command = malloc_sprintf("\"\"%s\" \"%s\" -o \"%s\" %s\"", gcc, objpath, exepath, linker_flags); - } else { - // Use clang from PATH. Convenient when developing Jou locally. - command = malloc_sprintf("clang \"%s\" -o \"%s\" %s", objpath, exepath, linker_flags); - } - free(gcc); + // Assume mingw with clang has been downloaded with windows_setup.sh + // Windows quoting is weird. The outermost quotes get stripped here. + command = malloc_sprintf("\"\"%s\\mingw64\\bin\\clang.exe\" \"%s\" -o \"%s\" %s\"", instdir, objpath, exepath, linker_flags); #else // Assume clang is installed and use it to link. Could use lld, but clang is needed anyway. (void)instdir;