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

fetch-configlet scripts: Add arm64 support #122

Open
ee7 opened this issue Jan 15, 2021 · 0 comments
Open

fetch-configlet scripts: Add arm64 support #122

ee7 opened this issue Jan 15, 2021 · 0 comments
Labels
kind: feature User-facing enhancement priority: high More important

Comments

@ee7
Copy link
Member

ee7 commented Jan 15, 2021

Similar to issue #24, but for the fetch scripts (which already have 32-bit support).

The v2 configlet released ARM binaries, but the fetch-configlet script there never supported downloading them.

This will become a more important issue as more people start using the latest ARM-based Mac machines with the Apple M1 chip.

@ee7 ee7 added the kind: feature User-facing enhancement label May 10, 2021
ee7 added a commit that referenced this issue Aug 16, 2023
Add a script to install Zig, and add a job to the build workflow that
uses `zig cc` to cross compile configlet for arm64 (AKA aarch64) Linux.

This means that the next configlet release will have two new release
assets:

    configlet_4.0.0-beta.14_linux_arm64.tar.gz
    configlet_4.0.0-beta.14_linux_arm64.tar.gz.minisig

and extracting the archive will yield the executable:

    $ file ./configlet
    ./configlet: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped

Also support running `nimble build -d:zig` locally.

For now, the new executable has a large comment section:

    $ readelf -p .comment ./configlet

    String dump of section '.comment':
      [     0]  clang version 16.0.6 (https://github.com/ziglang/zig-bootstrap 1dda86241204c4649f668d46b6a37feed707c7b4)
      [...] (repeat for 39 KiB)
      [  8d82]  clang version 16.0.6 (https://github.com/ziglang/zig-bootstrap 1dda86241204c4649f668d46b6a37feed707c7b4)
      [  8deb]  Linker: LLD 16.0.6

Try to strip it later. Our `strip` doesn't support elf64-aarch64 as a
target, and `zig objcopy` doesn't have a `-R, --remove-section` option
currently. But prepare to use `llvm-strip`.

Cross-compiling for arm64 macos currently produces an error:

    CC: ../nimdir/lib/std/sysrand.nim
    /home/runner/.cache/nim/configlet_r/@m..@snimdir@slib@sstd@ssysrand.nim.c:9:10:
    fatal error: 'Security/SecRandom.h' file not found

which is due to a recent commit [1].

See some posts on cross-compiling with Zig [2][3][4] and the support table [5].

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

[1] 53a75a2 ("nimble, uuid: generate UUIDs via std/sysrand, not pragmagic/uuids", 2023-08-07)
[2] https://ziglang.org/learn/overview/#cross-compiling-is-a-first-class-use-case
[3] https://andrewkelley.me/post/zig-cc-powerful-drop-in-replacement-gcc-clang.html
[4] https://www.uber.com/blog/bootstrapping-ubers-infrastructure-on-arm64-with-zig/
[5] https://ziglang.org/download/0.11.0/release-notes.html#Support-Table
ee7 added a commit that referenced this issue Aug 17, 2023
Continue the recent `zig cc` work [1], such that the next configlet
release will have two new release assets:

    configlet_4.0.0-beta.14_macos_arm64.tar.gz
    configlet_4.0.0-beta.14_macos_arm64.tar.gz.minisig

where the archive contains the executable:

    $ file ./configlet
    configlet: Mach-O 64-bit arm64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE|HAS_TLV_DESCRIPTORS>

`configlet uuid` now uses [2] `std/sysrand`, which on macOS uses [3] the
Security Framework. So to produce the macOS arm64 configlet, it's
easiest to cross-compile from macOS x86_64, where the macOSX SDK is
already available. Make the cross-compile and install-zig scripts
support macOS, and add a build job for it.

It looks like the macos-12 GitHub runner has SDK versions 12.3 and 13.1
installed. Use the latest one.

The new executable is about 1.09 MiB, which is notably larger than the
655 KiB macOS x86_64 executable. Possible ways to reduce the size in
the future:

- Enable LTO when `zig ld` supports it [4].

- Compile it natively, when GitHub begins to provide a hosted arm64
  macOS runner [5].

- Compile it natively, using a non-GitHub arm64 macOS runner.

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

[1] 0e8d665, ".github, config: use Zig to cross-compile arm64 Linux asset", 2023-08-13
[2] 53a75a2, "nimble, uuid: generate UUIDs via std/sysrand, not pragmagic/uuids", 2023-08-07
[3] https://github.com/nim-lang/Nim/blob/v2.0.0/lib/std/sysrand.nim#L235-L256
[4] https://www.github.com/ziglang/zig/issues/8680
[5] https://www.github.com/github/roadmap/issues/528
ee7 added a commit that referenced this issue Aug 18, 2023
Continue the recent `zig cc` work [1][2][3], 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 [4].

Also make the cross-compilation jobs and scripts work on Windows, even
though we currently cross-compile the new executable from Linux.

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

[1] 0e8d665, 2023-08-16, ".github, config: use Zig to cross-compile arm64 Linux asset"
[2] f280445, 2023-08-17, ".github: cross-compile arm64 macOS asset"
[3] a962b18, 2023-08-17, ".github: cross-compile riscv64 Linux asset"
[4] https://ziglang.org/download/0.11.0/release-notes.html#Support-Table
@ee7 ee7 added the priority: high More important label Aug 19, 2023
@ee7 ee7 changed the title fetch-configlet scripts: Add ARM support fetch-configlet scripts: Add arm64 support Aug 19, 2023
ee7 added a commit that referenced this issue Aug 22, 2023
The most recent configlet release [1] includes pre-built binaries for:

- arm64 Linux [2]
- arm64 macOS [3]
- arm64 Windows [4]
- riscv64 Linux [5]

Support arm64 in the bash fetch-configlet script.

Refs: #122

[1] https://github.com/exercism/configlet/releases/tag/4.0.0-beta.14
[2] 0e8d665, 2023-08-16, ".github, config: use Zig to cross-compile arm64 Linux asset"
[3] f280445, 2023-08-17, ".github: cross-compile arm64 macOS asset"
[4] 3824299, 2023-08-18, ".github, cli, completion: cross-compile arm64 Windows asset"
[5] a962b18, 2023-08-17, ".github: cross-compile riscv64 Linux asset"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature User-facing enhancement priority: high More important
Projects
None yet
Development

No branches or pull requests

1 participant