Skip to content

Commit

Permalink
.github, cli, completion: cross-compile arm64 Windows asset (#797)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ee7 committed Aug 18, 2023
1 parent a962b18 commit 3824299
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
20 changes: 18 additions & 2 deletions .github/bin/cross-compile
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions .github/bin/install-zig
Expand Up @@ -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}"
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Expand Up @@ -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:
Expand All @@ -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 }}
Expand Down
3 changes: 1 addition & 2 deletions src/cli.nim
Expand Up @@ -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}
Expand Down
8 changes: 7 additions & 1 deletion src/completion/completion.nim
Expand Up @@ -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()
Expand Down

0 comments on commit 3824299

Please sign in to comment.