From 3824299df1dda6b020a22c21a18808a5da29f757 Mon Sep 17 00:00:00 2001 From: ee7 <45465154+ee7@users.noreply.github.com> Date: Fri, 18 Aug 2023 08:35:28 +0200 Subject: [PATCH] .github, cli, completion: cross-compile arm64 Windows asset (#797) 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] 0e8d6659e43d, 2023-08-16, ".github, config: use Zig to cross-compile arm64 Linux asset" [2] f280445978c1, 2023-08-17, ".github: cross-compile arm64 macOS asset" [3] a962b181b54e, 2023-08-17, ".github: cross-compile riscv64 Linux asset" [4] https://ziglang.org/download/0.11.0/release-notes.html#Support-Table --- .github/bin/cross-compile | 20 ++++++++++++++++++-- .github/bin/install-zig | 8 ++++---- .github/workflows/build.yml | 5 +++++ src/cli.nim | 3 +-- src/completion/completion.nim | 8 +++++++- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/bin/cross-compile b/.github/bin/cross-compile index b1c12a4d..67e316ba 100755 --- a/.github/bin/cross-compile +++ b/.github/bin/cross-compile @@ -42,14 +42,30 @@ cross_compile() { fi nimble --verbose build "${build_options[@]}" + local binary_name='configlet' if command -v llvm-strip &> /dev/null; then echo "stripping large comment section from executable..." >&2 llvm-strip -R .comment "${binary_name}" fi + if command -v file &> /dev/null; then + file "${binary_name}" + fi + if command -v llvm-readobj &> /dev/null; then + llvm-readobj "${binary_name}" + fi + mkdir -p "${archives_dir}" - local archive="${archives_dir}/${binary_name}_${build_tag}_${os}_${arch}.tar.gz" - tar -cvzf "${archive}" "${binary_name}" + local archive_base="${archives_dir}/${binary_name}_${build_tag}_${os}_${arch}" + case "${os}" in + linux | macos) + tar -cvzf "${archive_base}.tar.gz" "${binary_name}" + ;; + windows) + mv "${binary_name}" "${binary_name}".exe + 7z a "${archive_base}.zip" "${binary_name}.exe" + ;; + esac } main() { diff --git a/.github/bin/install-zig b/.github/bin/install-zig index 4b1247c0..0708f4fd 100755 --- a/.github/bin/install-zig +++ b/.github/bin/install-zig @@ -44,16 +44,16 @@ case "${os}" in archive_sha256='1c1c6b9a906b42baae73656e24e108fd8444bb50b6e8fd03e9e7a3f8b5f05686' shasum -a 256 -c <<< "${archive_sha256} *${archive}" ;; - *) - echo "${os} not yet supported" >&2 - exit 1 + windows) + archive_sha256='142caa3b804d86b4752556c9b6b039b7517a08afa3af842645c7e2dcd125f652' + # TODO: check windows archive checksum ;; esac # Extract the archive, then remove it. echo "Extracting archive..." >&2 case "${ext}" in - *zip) unzip "${archive}" ;; + *zip) unzip -q "${archive}" ;; *) tar xJf "${archive}" ;; esac rm "${archive}" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c063d55..827737a1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -87,6 +87,9 @@ jobs: - runs-on: macos-12 zig_target: aarch64-macos-none + - runs-on: ubuntu-22.04 + zig_target: aarch64-windows-gnu + name: "${{ matrix.zig_target }}" runs-on: ${{ matrix.runs-on }} permissions: @@ -103,9 +106,11 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Install Zig + shell: bash run: ./.github/bin/install-zig - name: Cross-compile + shell: bash run: ./.github/bin/cross-compile env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/cli.nim b/src/cli.nim index c6859051..32b287d5 100644 --- a/src/cli.nim +++ b/src/cli.nim @@ -116,8 +116,7 @@ func genShortKeys: array[Opt, char] = result[opt] = ($opt)[0] const - repoRootDir = currentSourcePath().parentDir().parentDir() - configletVersion = staticRead(repoRootDir / "configlet.version").strip() + configletVersion = staticRead("../configlet.version").strip() short = genShortKeys() optsNoVal = {optHelp, optVersion, optFmtSyncUpdate, optFmtSyncYes, optInfoSyncOffline, optSyncDocs, optSyncFilepaths, optSyncMetadata} diff --git a/src/completion/completion.nim b/src/completion/completion.nim index a322786e..fe5a7851 100644 --- a/src/completion/completion.nim +++ b/src/completion/completion.nim @@ -6,7 +6,13 @@ proc readCompletions: array[Shell, string] = const repoRootDir = currentSourcePath().parentDir().parentDir().parentDir() const completionsDir = repoRootDir / "completions" for shell in sBash .. result.high: - result[shell] = staticRead(completionsDir / &"configlet.{shell}").compress() + # When cross-compiling for Windows from Linux, replace the `\\` DirSep with `/`. + var path = completionsDir / &"configlet.{shell}" + when defined(windows) and defined(zig) and staticExec("uname") == "Linux": + for c in path.mitems: + if c == '\\': + c = '/' + result[shell] = staticRead(path).compress() proc completion*(shellKind: Shell) = const completions = readCompletions()