Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.github, cli, completion: cross-compile arm64 Windows asset #797

Merged
merged 20 commits into from
Aug 18, 2023

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Aug 16, 2023

Continue the recent zig cc work, such that the next configlet release will have two new release assets:

configlet_4.0.0-beta.14_windows_arm64.zip
configlet_4.0.0-beta.14_windows_arm64.zip.minisig

where the archive contains the executable:

$ file ./configlet.exe
./configlet: PE32+ executable (console) Aarch64, for MS Windows, 6 sections

The aarch64-windows-gnu target will have Tier 1 Zig support.

Refs: #24
Refs: #122
Closes: #764


To-do:

  • Compress as .zip, not .tar.gz
  • Make it actually output a Windows arm64 executable, not x86_64
  • Final nitpicks

@ee7 ee7 force-pushed the github-cross-windows branch from 77b3c1c to 80fd33b Compare August 17, 2023 08:26
@ee7 ee7 force-pushed the github-cross-windows branch from 80fd33b to 672ddad Compare August 17, 2023 10:00
@ee7 ee7 mentioned this pull request Aug 17, 2023
17 tasks
ee7 added 3 commits August 17, 2023 12:11
The new job indicated success, but didn't upload an executable.

This was because on the Windows runner, the default shell is PowerShell:

    Run ./.github/bin/install-zig
      ./.github/bin/install-zig
      shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"

Explicitly set the shell to bash for every cross compilation job.
Fix error:

    CC: configlet.nim
    Hint:  [Link]
    Hint: mm: refc; threads: on; opt: size; options: -d:release
    92399 lines; 54.815s; 167.895MiB peakmem; proj: D:\a\configlet\configlet\src\configlet.nim; out: D:\a\configlet\configlet\configlet.exe [SuccessX]
         Info:  Nimble data file "C:\Users\runneradmin\.nimble\nimbledata2.json" has been saved.
    stripping large comment section from executable...
    C:\Program Files\LLVM\bin\llvm-strip.exe: error: 'configlet': no such file or directory

(It turns out that `llvm-strip` is installed in the Windows runners).
Some llvm-strip usage:

  --remove-section=section
                         Remove <section>
  -R <value>             Alias for --remove-section
  --strip-all-gnu        Compatible with GNU's --strip-all
  --strip-all            Remove non-allocated sections outside segments. .gnu.warning* and .ARM.attribute sections are not removed
  --strip-debug          Remove all debug sections
  --strip-sections       Remove all section headers and all sections not in segments
  --strip-symbol=symbol  Strip <symbol>
  --strip-unneeded       Remove all symbols not needed by relocations
  -S                     Alias for --strip-debug
  -s                     Alias for --strip-all
@ee7
Copy link
Member Author

ee7 commented Aug 17, 2023

The build workflow ran successfully and created this release, which has an arm64 Windows asset. (Edit: it was actually a x86_64 asset in disguise)

@ErikSchierboom Do you have access to an arm64 Windows machine? If so, could you test the above configlet?

@ee7 ee7 marked this pull request as ready for review August 17, 2023 11:26
@ee7 ee7 requested a review from ErikSchierboom as a code owner August 17, 2023 11:26
@ee7
Copy link
Member Author

ee7 commented Aug 17, 2023

Hmm, why does file say that the new executable is x86-64?

I'll see if not stripping makes a difference, but I'd guess that the executable really is x86-64 right now.

@ee7 ee7 mentioned this pull request Aug 17, 2023
@ErikSchierboom
Copy link
Member

@ErikSchierboom Do you have access to an arm64 Windows machine? If so, could you test the above configlet?

Unfortunately I don't. Maybe ask on the forum?

ee7 added 4 commits August 17, 2023 19:28
Try to suppress 10,000 lines of output. It printed a line for each
extracted file.
dumpbin probably exists somewhere on the runner, but it wasn't found.
@ee7
Copy link
Member Author

ee7 commented Aug 17, 2023

I don't understand why it seems to be outputting an x86_64 executable:

$ .github/bin/cross-compile
[...]
  Executing D:\a\configlet\configlet\nimdir\bin\nim.exe c --colors:on --noNimblePath \
-d:release --cpu:arm64 --os:windows -d:zig -d:target:aarch64-windows-gnu \
-d:NimblePkgVersion=4.0.0 \
--path:C:\Users\runneradmin\.nimble\pkgs2\parsetoml-0.7.1-586fe63467a674008c4445ed1b8ac882177d7103 \
--path:C:\Users\runneradmin\.nimble\pkgs2\jsony-1.1.5-6aeb83e7481ca8686396a568096054bc668294df \
--path:C:\Users\runneradmin\.nimble\pkgs2\supersnappy-2.1.3-36a05ee6befe3764ed8e2a6fb5d0882c2fd090f8 \
-o:D:\a\configlet\configlet\configlet.exe D:\a\configlet\configlet\src\configlet.nim
Hint: used config file 'D:\a\configlet\configlet\nimdir\config\nim.cfg' [Conf]
Hint: used config file 'D:\a\configlet\configlet\nimdir\config\config.nims' [Conf]
Hint: used config file 'D:\a\configlet\configlet\config.nims' [Conf]
...................................................................................................................................................
D:\a\configlet\configlet\src\patched_stdlib\json.nim(1[23](https://github.com/exercism/configlet/actions/runs/5894684581/job/15988813028#step:5:24)3, 7) Hint: 'typInst' is declared but not used [XDeclaredButNotUsed]
...............................................
D:\a\configlet\configlet\nimdir\lib\posix\posix.nim(1155, 13) Hint: 'sig' is declared but not used [XDeclaredButNotUsed]
CC: ../nimdir/lib/system/exceptions.nim
[...]
CC: configlet.nim
Hint:  [Link]
Hint: mm: refc; threads: on; opt: size; options: -d:release
92399 lines; 54.335s; 167.895MiB peakmem; proj: D:\a\configlet\configlet\src\configlet.nim; out: D:\a\configlet\configlet\configlet.exe [SuccessX]
$ llvm-readobj configlet.exe
File: configlet.exe
Format: COFF-x86-64
Arch: x86_64
AddressSize: 64bit

@ErikSchierboom
Copy link
Member

Could it be a Zig issue? Maybe try compiling a non-Nim Zig application first? Just to confirm that Zig can actually do the cross compiling to Windows Arm 64

@ee7
Copy link
Member Author

ee7 commented Aug 17, 2023

Yeah, Zig can do that. And it works for me locally:

$ nimble build -d:release -d:zig --cpu:arm64 --os:windows -d:target:aarch64-windows-gnu
$ file ./configlet
./configlet: PE32+ executable (console) Aarch64, for MS Windows, 6 sections
$ llvm-readobj ./configlet
File: ./configlet
Format: COFF-ARM64
Arch: aarch64
AddressSize: 64bit

So I suspect that we might fix this problem if we cross compile from x86_64 Linux, rather than x86_64 Windows. But I don't know why.

Anyway, I'll try that now.

ee7 added 4 commits August 17, 2023 21:15
Rather than from x86_64 windows, which seemed to produce an x86_64
executable:

    $ llvm-readobj configlet.exe
    File: configlet.exe
    Format: COFF-x86-64
    Arch: x86_64
    AddressSize: 64bit

despite compiling with:

    --cpu:arm64 --os:windows -d:zig -d:target:aarch64-windows-gnu
When cross-compiling from Linux to Windows:

- output the executable with a `.exe` file extension, by passing -o to
  Nim

- fix error for `llvm-readobj` not found
…to Windows"

This reverts commit 92a278d.

Nim gets passed

    -o:/home/runner/work/configlet/configlet/configlet

which overwrites the given

    -o:configlet.exe
@ee7
Copy link
Member Author

ee7 commented Aug 17, 2023

So I suspect that we might fix this problem if we cross compile from x86_64 Linux, rather than x86_64 Windows.

Yeah, that did it:

configlet: PE32+ executable (console) Aarch64, for MS Windows

@ErikSchierboom
Copy link
Member

Somewhat odd and unexpected, but 🤷‍♂️

ee7 added 4 commits August 18, 2023 07:42
Decrease the diff size of the current PR.

This won't do anything currently, since we don't do any cross-compiling
on a machine where llvm-strip is available.
Make it work on Linux, macOS, and Windows.
This reverts commit 8318c80.

Do this in a follow-up PR.
Not used for now. Reduce the PR diff size.
@ee7 ee7 merged commit 3824299 into exercism:main Aug 18, 2023
@ee7 ee7 deleted the github-cross-windows branch August 18, 2023 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aarch64 build target for release
2 participants