├── .editorconfig ├── .githooks └── pre-commit ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST │ └── pull_request_template.md └── workflows │ ├── build.yml │ └── lint.yml ├── .gitignore ├── .lintball-version ├── .lintballrc.json ├── .shellcheckrc ├── .yamllint.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin ├── download ├── exec-env ├── help.deps ├── help.links ├── help.overview ├── install ├── list-all └── list-bin-paths ├── contributing.md ├── lib ├── commands │ └── command-install-deps.bash └── utils.bash ├── package.json ├── renovate.json ├── scripts ├── ci-install.sh └── ci-test-plugin.sh ├── shims └── nimble └── test ├── integration.bats ├── lib └── test_utils.bash └── utils.bats /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /.githooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Run lintball using Docker on git commit 4 | 5 | set -eu 6 | 7 | workspace=$(git rev-parse --show-toplevel || true) 8 | if [[ -z ${workspace} ]]; then 9 | echo "Could not determine git repository path" >&2 10 | exit 1 11 | fi 12 | 13 | if [[ -f "${workspace}/scripts/build-local-docker-image.sh" ]]; then 14 | # This is lintball itself, build and use the local image 15 | "${workspace}/scripts/build-local-docker-image.sh" 16 | image=lintball:local 17 | else 18 | image=elijahru/lintball:latest 19 | fi 20 | 21 | docker run -v "${workspace}:/workspace" "${image}" lintball pre-commit 22 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @asdf-community/asdf-nim 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "" 5 | labels: bug 6 | assignees: "" 7 | --- 8 | 9 | **Describe the bug** 10 | 11 | 12 | 13 | **Steps to reproduce** 14 | 15 | 16 | 17 | **Expected behavior** 18 | 19 | 20 | 21 | **Screenshots** 22 | 23 | 24 | 25 | **Additional context** 26 | 27 | 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "" 5 | labels: enhancement 6 | assignees: "" 7 | --- 8 | 9 | **Is your feature request related to a problem? Please describe.** 10 | 11 | 12 | 13 | **Describe the solution you'd like** 14 | 15 | 16 | 17 | **Describe alternatives you've considered** 18 | 19 | 20 | 21 | **Additional context** 22 | 23 | 24 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | 6 | 7 | ## Motivation and Context 8 | 9 | 10 | 11 | 12 | ## Types of changes 13 | 14 | 15 | 16 | - [ ] Bug fix (non-breaking change which fixes an issue) 17 | - [ ] New feature (non-breaking change which adds functionality) 18 | - [ ] Breaking change (fix or feature that would cause existing functionality to change) 19 | 20 | ## Usage examples 21 | 22 | 23 | 24 | ## How Has This Been Tested? 25 | 26 | 27 | 28 | ## Checklist: 29 | 30 | 31 | 32 | 33 | - [ ] I have updated the documentation accordingly. 34 | - [ ] I have added tests to cover my changes. 35 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # yamllint disable rule:line-length 2 | 3 | name: build 4 | 5 | # yamllint disable rule:truthy 6 | on: 7 | # yamllint enable rule:truthy 8 | workflow_dispatch: {} 9 | pull_request: 10 | branches: ["*"] 11 | paths: 12 | - .github/workflows/build.yml # changes to this file 13 | - bin/** # changes to asdf entrypoint scripts 14 | - lib/** # changes to library functions 15 | - share/** # changes to data files 16 | - shims/** # changes to shim scripts 17 | - test/** # changes to tests 18 | - package*.json # bats upgrade 19 | push: 20 | branches: ["main"] 21 | tags: ["*"] 22 | paths: 23 | - .github/workflows/build.yml # changes to this file 24 | - bin/** # changes to asdf entrypoint scripts 25 | - lib/** # changes to library functions 26 | - share/** # changes to data files 27 | - shims/** # changes to shim scripts 28 | - test/** # changes to tests 29 | - package*.json # bats upgrade 30 | 31 | jobs: 32 | # Run tests with bats 33 | bats_tests: 34 | name: Bats tests 35 | runs-on: ubuntu-latest 36 | 37 | env: 38 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | 40 | steps: 41 | - name: Checkout plugin 42 | uses: actions/checkout@v4 43 | 44 | - uses: actions/setup-node@v4 45 | with: 46 | node-version: "22" 47 | 48 | - name: Run tests 49 | run: | 50 | npm install --include=dev 51 | [ -n "$(which bats)" ] || npm link bats 52 | npm run test -- --jobs 4 53 | 54 | plugin_test_x86: 55 | name: 👑${{ matrix.nim-version }}/${{ matrix.platform }}/x86_64 56 | runs-on: ${{ matrix.os }} 57 | 58 | strategy: 59 | fail-fast: false 60 | matrix: 61 | include: 62 | # Stable binary 63 | - os: ubuntu-latest 64 | nim-version: "latest:1.6" 65 | platform: linux-glibc 66 | 67 | # Stable binary 68 | - os: ubuntu-latest 69 | nim-version: "latest:2.2" 70 | platform: linux-glibc 71 | 72 | # Unstable binary 73 | - os: ubuntu-latest 74 | nim-version: "ref:version-2-0" 75 | platform: linux-glibc 76 | 77 | # Unstable binary 78 | - os: macos-latest 79 | nim-version: "ref:devel" 80 | platform: macOS 81 | 82 | # Build from source 83 | - os: ubuntu-latest 84 | nim-version: "ref:HEAD" 85 | platform: linux-glibc 86 | 87 | # Build from source 88 | - os: macos-latest 89 | nim-version: "latest:2.2" 90 | platform: macOS 91 | 92 | steps: 93 | # Optimization: re-use cached Nim->C compilation 94 | - name: Restore cache 95 | if: matrix.nim-version != 'ref:HEAD' && matrix.nim-version != 'latest' 96 | uses: actions/cache@v4 97 | with: 98 | path: ~/.cache 99 | key: cache-${{ matrix.os }}-${{ matrix.nim-version }} 100 | 101 | - name: Install dependencies (macOS) 102 | if: runner.os == 'macOS' 103 | run: brew install bash parallel golang 104 | 105 | - name: Install dependencies (Linux) 106 | if: runner.os != 'macOS' 107 | uses: actions/setup-go@v5 108 | 109 | - name: Install asdf 110 | run: go install github.com/asdf-vm/asdf/cmd/asdf@master 111 | 112 | - name: Checkout plugin 113 | uses: actions/checkout@v4 114 | 115 | - name: Test plugin 116 | shell: bash 117 | run: | 118 | exec ./scripts/ci-test-plugin.sh \ 119 | --nim-version ${{ matrix.nim-version }} 120 | 121 | # Test musl installation 122 | plugin_test_x86_musl: 123 | name: 👑2.2.x/linux-musl/x86_64 124 | runs-on: ubuntu-latest 125 | container: alpine:latest 126 | 127 | steps: 128 | # Optimization: re-use cached Nim->C compilation 129 | - name: Restore cache 130 | uses: actions/cache@v4 131 | with: 132 | path: ~/.cache 133 | key: cache-ubuntu-latest-2.2.4 134 | 135 | - name: Install dependencies 136 | run: apk add --update --no-cache --upgrade bash git curl coreutils tar xz grep build-base go 137 | 138 | - name: Install asdf 139 | run: go install github.com/asdf-vm/asdf/cmd/asdf@master 140 | 141 | - name: Checkout plugin 142 | uses: actions/checkout@v4 143 | 144 | - name: Test plugin 145 | shell: bash 146 | run: | 147 | exec ./scripts/ci-test-plugin.sh \ 148 | --nim-version latest:2.2 149 | 150 | # Test installation for a few non-x86 architectures 151 | plugin_test_non_x86: 152 | name: 👑${{ matrix.nim-version }}/linux-glibc/${{ matrix.arch }} 153 | runs-on: ubuntu-latest 154 | 155 | strategy: 156 | fail-fast: false 157 | matrix: 158 | include: 159 | # Unstable binary 160 | - runs-on: ubuntu-latest 161 | nim-version: "ref:version-2-2" 162 | arch: aarch64 163 | 164 | # Unstable binary 165 | - runs-on: ubuntu-latest 166 | nim-version: "ref:version-1-6" 167 | arch: armv7 168 | 169 | steps: 170 | # Optimization: re-use cached Nim->C compilation 171 | - name: Restore cache 172 | uses: actions/cache@v4 173 | with: 174 | path: ~/.cache 175 | key: cache-${{ matrix.arch }}-${{ matrix.nim-version }} 176 | 177 | - name: Checkout plugin 178 | uses: actions/checkout@v4 179 | 180 | # Install & run tests on non-x86 181 | - uses: uraimo/run-on-arch-action@v3 182 | name: Test plugin 183 | with: 184 | arch: ${{ matrix.arch }} 185 | distro: bookworm 186 | dockerRunArgs: | 187 | --volume "${HOME}/.cache:/root/.cache" 188 | --volume "${GITHUB_WORKSPACE}:/workspace" 189 | shell: /usr/bin/env bash 190 | setup: | 191 | mkdir -p "${HOME}/.cache" 192 | run: | 193 | set -uexo pipefail 194 | cd /workspace 195 | ./scripts/ci-install.sh 196 | exec ./scripts/ci-test-plugin.sh \ 197 | --nim-version ${{ matrix.nim-version }} 198 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | # yamllint disable rule:truthy 3 | on: 4 | pull_request: 5 | branches: ["*"] 6 | push: 7 | branches: ["*"] 8 | tags: ["*"] 9 | # yamllint enable rule:truthy 10 | 11 | jobs: 12 | lint: 13 | name: lint 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - name: Checkout code 19 | uses: actions/checkout@v4 20 | with: 21 | fetch-depth: 0 # This is necessary for linting only recent changes 22 | 23 | - name: Run lintball 24 | uses: elijahr/run-lintball@v2 25 | with: 26 | default-branch: main 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.vscode 2 | testnimble* 3 | /node_modules 4 | /.tool-versions 5 | package-lock.json 6 | /.tmp 7 | /nimbledeps 8 | -------------------------------------------------------------------------------- /.lintball-version: -------------------------------------------------------------------------------- 1 | v2.0.15 2 | -------------------------------------------------------------------------------- /.lintballrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "lintballrc_version": "2", 3 | "check_args": { 4 | "yamllint": [ 5 | "{{tool}}", 6 | "--format", 7 | "{{format}}", 8 | "--strict", 9 | "--config-file", 10 | "./.yamllint.yml", 11 | "{{path}}" 12 | ] 13 | }, 14 | "write_args": { 15 | "yamllint": [ 16 | "{{tool}}", 17 | "--format", 18 | "{{format}}", 19 | "--strict", 20 | "--config-file", 21 | "./.yamllint.yml", 22 | "{{path}}" 23 | ] 24 | }, 25 | "use": { 26 | "autoflake": false, 27 | "autopep8": false, 28 | "black": false, 29 | "docformatter": false, 30 | "isort": false, 31 | "prettier": true, 32 | "prettier-eslint": true, 33 | "pylint": false, 34 | "shellcheck": true, 35 | "shfmt": true, 36 | "yamllint": true 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /.shellcheckrc: -------------------------------------------------------------------------------- 1 | disable=SC2154,SC2312,SC2310 2 | -------------------------------------------------------------------------------- /.yamllint.yml: -------------------------------------------------------------------------------- 1 | yaml-files: 2 | - "*.yaml" 3 | - "*.yml" 4 | 5 | rules: 6 | braces: enable 7 | brackets: enable 8 | colons: enable 9 | commas: enable 10 | comments: disable 11 | comments-indentation: enable 12 | document-end: disable 13 | document-start: disable 14 | empty-lines: enable 15 | empty-values: disable 16 | hyphens: enable 17 | indentation: enable 18 | key-duplicates: enable 19 | key-ordering: disable 20 | line-length: disable 21 | new-line-at-end-of-file: enable 22 | new-lines: enable 23 | octal-values: disable 24 | quoted-strings: disable 25 | trailing-spaces: enable 26 | truthy: enable 27 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). 6 | 7 | ## v2.1.0 - 2025-06-07 8 | 9 | - fixes and workarounds for asdf >= 0.17.0 10 | - remove docker files 11 | - build action improvements 12 | 13 | ## v2.0.2 - 2024-11-06 14 | 15 | - test against newer nims 16 | - update documentation for newer nims 17 | - upgrade lintball 18 | 19 | ## v2.0.1 - 2022-11-28 20 | 21 | - fix: sorting for `asdf list-all nim` 22 | 23 | ## v2.0.0 - 2022-11-08 24 | 25 | - add: nightly unstable binary support (ire4ever1190) 26 | - add: docker-compose config for Linux development 27 | - improve: linting (yaml, markdown, update shellcheck/shfmt) 28 | - remove: unofficial binaries from nim-builds 29 | - remove: hub dependency 30 | - remove: untested windows support (does asdf even support mingw bash?) 31 | - fix: fixed ASDF_INSTALL_PATH empty when version is ref:HEAD (joxcat) 32 | 33 | ## v1.4.0 - 2022-05-10 34 | 35 | - add: binaries for Nim 1.2.18, 1.6.4, 1.6.6 36 | 37 | ### v1.3.2 - 2021-12-27 38 | 39 | - fix: #14 ASDF_DATA_DIR default not sensible 40 | 41 | ### v1.3.1 - 2021-12-24 42 | 43 | - add: binaries for Nim 1.2.16 and 1.6.2 44 | 45 | ### v1.3.0 - 2021-11-30 46 | 47 | - fix: don't override XDG_CONFIG_HOME and APPDATA 48 | 49 | ### v1.2.3 - 2021-11-22 50 | 51 | - fix: workaround for M1 `DYLD_LIBRARY_PATH` 52 | 53 | ### v1.2.1 - 2021-10-12 54 | 55 | - fix: `asdf_nim_is_musl ` check 56 | 57 | ### v1.2.0 - 2021-10-09 58 | 59 | - fix: missing `tools` directory 60 | - deprecate: remove `ASDF_NIM_REQUIRE_BINARY` option 61 | 62 | ### v1.1.6 - 2021-10-08 63 | 64 | - fix: CI: plugin test on Alpine Linux failed due to busybox grep missing -quiet 65 | - fix: ASDF_INSTALL_PATH should not be assumed as set due to `list-all` 66 | 67 | - ### v1.1.5 - 2021-7-11 68 | 69 | - fix: Support for nimbledeps directory (#7) 70 | 71 | ### v1.1.4 - 2021-03-27 72 | 73 | - fix: bats issues 74 | 75 | ### v1.1.3 - 2021-03-04 76 | 77 | - feat: allow nimble shim to work in elvish shell 78 | 79 | ### v1.1.2 - 2021-01-30 80 | 81 | - feat: support for Apple Silicon / M1 82 | 83 | ### v1.1.1 - 2021-01-24 84 | 85 | - update: lintball 1.1.3 86 | 87 | ### v1.1.0 - 2021-01-18 88 | 89 | - feat: support for bash 3 90 | - fix: remove hard dependency on gcc for determining ARM version 91 | - fix: build issues on GitHub Actions 92 | - feat: reformat code with [lintball](https://github.com/elijahr/lintball) 93 | 94 | ### v1.0.0 - 2021-01-06 95 | 96 | - feat: refactor 97 | - fix: issues with nimble shim 98 | - feat: add unit & integration tests 99 | 100 | ### v0.2.1 - 2021-01-02 101 | 102 | - fix: issue with tarball name generation causing unnecessary building from source. 103 | 104 | ### v0.2.0 - 2021-01-02 105 | 106 | - fix: armv7 could not curl even with update-ca-certificates. Bundle latest cacert.pem. 107 | - fix: perms issue where asdf cleanup handler would block on rm of fusion/.git/\* files 108 | - workaround: CI: disable TCP offloading so can run macOS tests again 109 | - feat: add pre-commit git hooks for shfmt and prettier 110 | - feat: test on CI: Alpine / musl 111 | 112 | ### v0.1.0 - 2021-01-01 113 | 114 | - feat: initial release 115 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![build](https://github.com/asdf-community/asdf-nim/actions/workflows/build.yml/badge.svg)](https://github.com/asdf-community/asdf-nim/actions/workflows/build.yml) [![lint](https://github.com/asdf-community/asdf-nim/actions/workflows/lint.yml/badge.svg)](https://github.com/asdf-community/asdf-nim/actions/workflows/lint.yml) 2 | 3 | # asdf-nim 4 | 5 | asdf-nim allows you to quickly install any version of [Nim](https://nim-lang.org). 6 | 7 | asdf-nim works for both personal development and continuous integration. It runs on macOS and Linux, supporting x86, ARM, and other architectures. 8 | 9 | ## Installation 10 | 11 | [Install asdf](https://asdf-vm.com/guide/getting-started.html), then: 12 | 13 | ```sh 14 | asdf plugin add nim # install the asdf-nim plugin 15 | asdf nim install-deps # install system-specific dependencies for downloading & building Nim 16 | ``` 17 | 18 | ### To install Nim: 19 | 20 | When available for the version and platform, the plugin will install pre-compiled binaries of Nim. If no binaries are available the plugin will build Nim from source. 21 | 22 | ```sh 23 | # latest stable version of Nim 24 | asdf install nim latest 25 | # or latest stable minor/patch release of Nim 2.x.x 26 | asdf install nim latest:2 27 | # or latest stable patch release of Nim 2.2.x 28 | asdf install nim latest:2.2 29 | # or specific patch release 30 | asdf install nim 2.2.0 31 | ``` 32 | 33 | ### To install a nightly build of Nim: 34 | 35 | ```sh 36 | # nightly unstable build of devel branch 37 | asdf install nim ref:devel 38 | # or nightly unstable build of version-2-2 branch, i.e. the 2.2.x release + any recent backports from devel 39 | asdf install nim ref:version-2-2 40 | # or nightly unstable build of version-1-6 branch, i.e. the latest 1.6.x release + any recent backports from devel 41 | asdf install nim ref:version-1-6 42 | ``` 43 | 44 | ### To build a specific git commit or branch of Nim: 45 | 46 | ```sh 47 | # build using latest commit from the devel branch 48 | asdf install nim ref:HEAD 49 | # build using the specific commit 7d15fdd 50 | asdf install nim ref:7d15fdd 51 | # build using the tagged release v2.2.0 52 | asdf install nim ref:v2.2.0 53 | ``` 54 | 55 | ### To set the default version of Nim for your user: 56 | 57 | ```sh 58 | asdf set --home nim latest:2.2 59 | ``` 60 | 61 | This creates a `.tool-versions` file in your home directory specifying the Nim version. 62 | 63 | ### To set the version of Nim for a project directory: 64 | 65 | ```sh 66 | cd my-project 67 | asdf set nim latest:2.2 68 | ``` 69 | 70 | This creates a `.tool-versions` file in the current directory specifying the Nim version. For additional plugin usage see the [asdf documentation](https://asdf-vm.com/#/core-manage-asdf). 71 | 72 | ## Nimble packages 73 | 74 | In addition to global nimble package installation, asdf-nim works as expected with a[`nimbledeps`](https://github.com/nim-lang/nimble/issues/131#issuecomment-676624533) directory and the [atlas](https://github.com/nim-lang/atlas) package cloner. 75 | 76 | ## Continuous Integration 77 | 78 | ### A simple example using GitHub Actions: 79 | 80 | ```yaml 81 | name: Build 82 | on: 83 | push: 84 | paths-ignore: 85 | - README.md 86 | 87 | env: 88 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 89 | 90 | jobs: 91 | build: 92 | name: Test 93 | runs-on: ${{ matrix.os }} 94 | matrix: 95 | include: 96 | # Test against stable Nim builds on linux 97 | - os: ubuntu-latest 98 | nim-version: latest:2.2 99 | - os: ubuntu-latest 100 | nim-version: latest:1.6 101 | 102 | # Test against unstable nightly Nim builds on macos x64 (faster than building from source) 103 | - os: macos-latest 104 | nim-version: ref:version-2-2 105 | - os: macos-latest 106 | nim-version: ref:version-1-6 107 | steps: 108 | - name: Checkout 109 | uses: actions/checkout@v4 110 | - name: Install Nim 111 | uses: asdf-vm/actions/install@v4 112 | with: 113 | tool_versions: | 114 | nim ${{ matrix.nim-version }} 115 | - name: Run tests 116 | run: | 117 | asdf set nim ${{ matrix.nim-version }} 118 | nimble develop -y 119 | nimble test 120 | nimble examples 121 | ``` 122 | 123 | ### Continuous Integration on Non-x86 Architectures 124 | 125 | Using [uraimo/run-on-arch-action](https://github.com/uraimo/run-on-arch-action): 126 | 127 | ```yaml 128 | name: Build 129 | on: 130 | push: 131 | paths-ignore: 132 | - README.md 133 | 134 | jobs: 135 | test_non_x86: 136 | name: Test nim-${{ matrix.nim-version }} / debian-buster / ${{ matrix.arch }} 137 | strategy: 138 | fail-fast: false 139 | matrix: 140 | include: 141 | - nim-version: ref:version-2-2 142 | arch: armv7 143 | - nim-version: ref:version-1-6 144 | arch: aarch64 145 | 146 | runs-on: ubuntu-latest 147 | steps: 148 | - name: Checkout Nim project 149 | uses: actions/checkout@v4 150 | 151 | - uses: uraimo/run-on-arch-action@v3 152 | name: Install Nim & run tests 153 | with: 154 | arch: ${{ matrix.arch }} 155 | distro: bookworm 156 | 157 | dockerRunArgs: | 158 | --volume "${HOME}/.cache:/root/.cache" 159 | --volume "${GITHUB_WORKSPACE}:/workspace" 160 | 161 | setup: mkdir -p "${HOME}/.cache" 162 | 163 | shell: /usr/bin/env bash 164 | 165 | install: | 166 | set -uexo pipefail 167 | 168 | # Add Debian backports repository for newer Golang versions 169 | cat >/etc/apt/sources.list.d/debian-backports.sources </asdf-nim.git ~/.asdf/plugins/nim 247 | ``` 248 | 249 | ### Testing 250 | 251 | This project uses [bats](https://github.com/bats-core/bats-core) for unit testing. Please follow existing patterns and add unit tests for your changeset. Dev dependencies for unit tests are installed via: 252 | 253 | ```shell 254 | cd ~/.asdf/plugins/nim 255 | npm install --include=dev 256 | ``` 257 | 258 | Run tests with: 259 | 260 | ```sh 261 | npm run test 262 | ``` 263 | 264 | ### Linting 265 | 266 | This project uses [lintball](https://github.com/elijahr/lintball) to auto-format code. Please ensure your changeset passes linting. Enable the githooks with: 267 | 268 | ```sh 269 | git config --local core.hooksPath .githooks 270 | ``` 271 | -------------------------------------------------------------------------------- /bin/download: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ueo pipefail 4 | shopt -s dotglob 5 | 6 | # shellcheck source=SCRIPTDIR/../lib/utils.bash 7 | source "$(dirname "${BASH_SOURCE[0]}")/../lib/utils.bash" 8 | 9 | asdf_nim_init "download" 10 | asdf_nim_init_traps 11 | 12 | # No exec {fd} redirection with bash 3 13 | # shellcheck disable=SC2001 14 | BASH_MAJOR_VERSION="$(echo "$BASH_VERSION" | sed 's/\..*//')" 15 | if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then 16 | exec {ASDF_NIM_STDOUT}<&1 {ASDF_NIM_STDERR}<&2 17 | { 18 | asdf_nim_download 19 | } 1>>"$(asdf_nim_log)" 2>>"$(asdf_nim_log)" 20 | else 21 | touch "$(asdf_nim_log)" 22 | asdf_nim_download 23 | fi 24 | -------------------------------------------------------------------------------- /bin/exec-env: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Workaround so Nim knows where to find Homebrew-installed dynamic libraries 4 | # on M1 Macs. On M1, Homebrew lives in /opt/homebrew instead of /usr/local. 5 | # So end users have to put something like DYLD_LIBRARY_PATH=/opt/homebrew/lib 6 | # in their shell init files. However, macOS has a security feature called SIP 7 | # which prevents certain env vars such as DYLD_LIBRARY_PATH from propagating 8 | # to /usr/bin/env child processes. So, we assume that if the user is on M1 macOS 9 | # and has Homebrew installed, they want to link to libraries there. To skip this 10 | # set ASDF_NIM_MACOS_M1_HOMEBREW_WORKAROUND=no in your environment. 11 | if [ "${ASDF_NIM_MACOS_M1_HOMEBREW_WORKAROUND:-yes}" = "yes" ] && 12 | [ "$(uname)" = "Darwin" ] && 13 | [ "$(uname -m)" = "arm64" ] && 14 | [ "${DYLD_LIBRARY_PATH-}" = "" ] && 15 | [ -d /opt/homebrew/lib ]; then 16 | export DYLD_LIBRARY_PATH 17 | DYLD_LIBRARY_PATH=/opt/homebrew/lib 18 | fi 19 | 20 | # Override PATH so this nim is found first 21 | export PATH 22 | PATH="${ASDF_INSTALL_PATH}/bin:${PATH}" 23 | 24 | export NIMBLE_DIR 25 | 26 | # Tell Nim where to find nimble package metadata and packages. 27 | # If a user has a custom NIMBLE_DIR, use that. 28 | # Otherwise if the current working directory has a nimbledeps directory, use that. 29 | # Otherwise, use the nimble directory within ASDF_INSTALL_PATH. 30 | # see https://github.com/nim-lang/nimble#nimbles-folder-structure-and-packages 31 | if [ "${NIMBLE_DIR-}" = "" ] && 32 | [ ! -d "${PWD}/nimbledeps" ]; then 33 | NIMBLE_DIR="${ASDF_INSTALL_PATH}/nimble" 34 | fi 35 | -------------------------------------------------------------------------------- /bin/help.deps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ueo pipefail 4 | shopt -s dotglob 5 | 6 | # shellcheck source=SCRIPTDIR/../lib/utils.bash 7 | source "$(dirname "${BASH_SOURCE[0]}")/../lib/utils.bash" 8 | 9 | echo "asdf-nim depends on the following packages:" 10 | asdf_nim_list_deps 11 | echo 12 | -------------------------------------------------------------------------------- /bin/help.links: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "https://github.com/asdf-community/asdf-nim" 4 | echo 5 | -------------------------------------------------------------------------------- /bin/help.overview: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck disable=SC2016 4 | 5 | echo 'This plugin installs the Nim compiler and tools (nimble, nimgrep, etc).' 6 | echo 7 | echo 'The tool will try to install pre-compiled binaries when available for' 8 | echo 'the version/platform, otherwise Nim is built from source.' 9 | echo 10 | echo 'Stable binaries:' 11 | echo '- Linux: x86_64 and x86 only' 12 | echo '- `asdf install nim X.Y.Z` for a specific version' 13 | echo '- `asdf install nim latest:X.Y` for the latest patch release of X.Y' 14 | echo 15 | echo 'Unstable binaries:' 16 | echo '- Linux: x86_64, x86, armv7l, aarch64' 17 | echo '- macOS: x86_64' 18 | echo '- `asdf install nim ref:devel` for the latest nightly build of github.com/nim-lang/Nim/tree/devel' 19 | echo '- `asdf install nim ref:version-2-0` for the latest nightly build of github.com/nim-lang/Nim/tree/version-2-0' 20 | echo '- `asdf install nim ref:version-1-4` for the latest nightly build of github.com/nim-lang/Nim/tree/version-1-4' 21 | echo '- etc' 22 | echo 23 | echo 'Source builds:' 24 | echo '- All platforms' 25 | echo '- `asdf install nim ref:`' 26 | echo '- `asdf install nim ref:vX.Y.Z` to force build for a specific stable version' 27 | echo 28 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ueo pipefail 4 | shopt -s dotglob 5 | 6 | # shellcheck source=SCRIPTDIR/../lib/utils.bash 7 | source "$(dirname "${BASH_SOURCE[0]}")/../lib/utils.bash" 8 | 9 | asdf_nim_init "install" 10 | asdf_nim_init_traps 11 | 12 | # Install Nim, building from source if necessary. 13 | # The installation will be placed in ASDF_INSTALL_PATH when complete. 14 | asdf_nim_install() { 15 | if [ "$ASDF_NIM_DEBUG" = "yes" ]; then 16 | set -x 17 | fi 18 | 19 | if [ "$(asdf_nim_needs_download)" = "yes" ]; then 20 | die "No nim source to build or archive to install." 21 | return 1 22 | fi 23 | 24 | asdf_nim_build 25 | section_start "III. Install (${ASDF_NIM_INSTALL_PATH//${HOME}/\~})" 26 | 27 | step_start "cp to ${ASDF_NIM_INSTALL_PATH//${HOME}/\~}" 28 | rm -rf "$ASDF_NIM_INSTALL_PATH" 29 | cp -R "$ASDF_DOWNLOAD_PATH" "$ASDF_NIM_INSTALL_PATH" 30 | step_end "✓" 31 | 32 | # Finalize installation 33 | step_start "mv to ${ASDF_INSTALL_PATH//${HOME}/\~}" 34 | rm -rf "$ASDF_INSTALL_PATH" 35 | mv -v "$ASDF_NIM_INSTALL_PATH" "$ASDF_INSTALL_PATH" 36 | step_end "✓" 37 | 38 | step_start "👑 installed Nim ${ASDF_INSTALL_VERSION}$(asdf_nim_time)" 39 | step_end "✓" 40 | 41 | if [ "$ASDF_NIM_DEBUG" = "yes" ]; then 42 | set +x 43 | fi 44 | } 45 | 46 | # No exec {fd} redirection with bash 3 47 | # shellcheck disable=SC2001 48 | BASH_MAJOR_VERSION="$(echo "$BASH_VERSION" | sed 's/\..*//')" 49 | if [ "$BASH_MAJOR_VERSION" -ge 4 ]; then 50 | exec {ASDF_NIM_STDOUT}<&1 {ASDF_NIM_STDERR}<&2 51 | { 52 | asdf_nim_install 53 | } 1>>"$(asdf_nim_log)" 2>>"$(asdf_nim_log)" 54 | else 55 | touch "$(asdf_nim_log)" 56 | asdf_nim_install 57 | fi 58 | -------------------------------------------------------------------------------- /bin/list-all: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ueo pipefail 4 | shopt -s dotglob 5 | 6 | # shellcheck source=SCRIPTDIR/../lib/utils.bash 7 | source "$(dirname "${BASH_SOURCE[0]}")/../lib/utils.bash" 8 | 9 | asdf_nim_list_all_versions | xargs printf '%s ' | sed 's/ $/\n/' 10 | -------------------------------------------------------------------------------- /bin/list-bin-paths: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "bin nimble/bin" 4 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Testing Locally: 4 | 5 | ```shell 6 | asdf plugin test [--asdf-tool-version ] [--asdf-plugin-gitref ] [test-command*] 7 | 8 | # 9 | asdf plugin test nim https://github.com/asdf-community/asdf-nim.git "nim -v" 10 | ``` 11 | 12 | Tests are automatically run in GitHub Actions on push and PR. 13 | -------------------------------------------------------------------------------- /lib/commands/command-install-deps.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -euo pipefail 4 | 5 | # shellcheck source=SCRIPTDIR/../utils.bash 6 | source "$(dirname "${BASH_SOURCE[0]}")/../utils.bash" 7 | 8 | ASDF_NIM_INSTALL_DEPS_ACCEPT="no" 9 | POSITIONAL=() 10 | while [[ $# -gt 0 ]]; do 11 | key="$1" 12 | 13 | case $key in 14 | -y | --yes) 15 | ASDF_NIM_INSTALL_DEPS_ACCEPT="yes" 16 | shift # past argument 17 | ;; 18 | *) # unknown option 19 | POSITIONAL+=("$1") # save it in an array for later 20 | shift # past argument 21 | ;; 22 | esac 23 | done 24 | 25 | asdf_nim_install_deps @POSITIONAL 26 | -------------------------------------------------------------------------------- /lib/utils.bash: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # shellcheck disable=SC2230 4 | 5 | # Constants 6 | SOURCE_REPO="https://github.com/nim-lang/Nim.git" 7 | SOURCE_URL="https://nim-lang.org/download/nim-VERSION.tar.xz" 8 | 9 | LINUX_X64_NIGHTLY_URL="https://github.com/nim-lang/nightlies/releases/download/latest-BRANCH/linux_x64.tar.xz" 10 | LINUX_X32_NIGHTLY_URL="https://github.com/nim-lang/nightlies/releases/download/latest-BRANCH/linux_x32.tar.xz" 11 | LINUX_ARM64_NIGHTLY_URL="https://github.com/nim-lang/nightlies/releases/download/latest-BRANCH/linux_arm64.tar.xz" 12 | LINUX_ARMV7L_NIGHTLY_URL="https://github.com/nim-lang/nightlies/releases/download/latest-BRANCH/linux_armv7l.tar.xz" 13 | MACOS_X64_NIGHTLY_URL="https://github.com/nim-lang/nightlies/releases/download/latest-BRANCH/macosx_x64.tar.xz" 14 | 15 | LINUX_X64_URL="https://nim-lang.org/download/nim-VERSION-linux_x64.tar.xz" 16 | LINUX_X32_URL="https://nim-lang.org/download/nim-VERSION-linux_x32.tar.xz" 17 | 18 | NIM_ARGS=("--parallelBuild:${ASDF_CONCURRENCY:-0}" "-d:release") # Args to pass to koch/nim 19 | 20 | normpath() { 21 | # Remove all /./ sequences. 22 | local path 23 | path="${1//\/.\//\/}" 24 | # Remove dir/.. sequences. 25 | while [[ $path =~ ([^/][^/]*/\.\./?) ]]; do 26 | path="${path/${BASH_REMATCH[0]}/}" 27 | done 28 | echo "$path" | sed 's/\/$//' 29 | } 30 | 31 | # Create the temp directories used by the download/build/install functions. 32 | asdf_nim_init() { 33 | export ASDF_NIM_ACTION 34 | ASDF_NIM_ACTION="$1" 35 | 36 | # Configuration options 37 | export ASDF_NIM_REMOVE_TEMP 38 | ASDF_NIM_REMOVE_TEMP="${ASDF_NIM_REMOVE_TEMP:-yes}" # If no, asdf-nim's temporary directory won't be deleted on exit 39 | export ASDF_NIM_DEBUG 40 | ASDF_NIM_DEBUG="${ASDF_NIM_DEBUG:-no}" # If yes, extra information will be logged to the console and every command executed will be logged to the logfile. 41 | export ASDF_NIM_STDOUT 42 | ASDF_NIM_STDOUT="${ASDF_NIM_STDOUT:-1}" # The file descriptor where the script's standard output should be directed. 43 | export ASDF_NIM_STDERR 44 | ASDF_NIM_STDERR="${ASDF_NIM_STDERR:-2}" # The file descriptor where the script's standard error output should be directed. 45 | export ASDF_NIM_SILENT 46 | ASDF_NIM_SILENT="${ASDF_NIM_SILENT:-no}" # If yes, asdf-nim will not echo build steps to stdout. 47 | # End configuration options 48 | 49 | # Ensure ASDF_DATA_DIR has a value 50 | if [ -n "${ASDF_INSTALL_PATH-}" ]; then 51 | export ASDF_DATA_DIR 52 | ASDF_DATA_DIR="${ASDF_DATA_DIR:-$HOME/.asdf}" 53 | export ASDF_NIM_TEMP 54 | ASDF_NIM_TEMP="${ASDF_DATA_DIR}/tmp/nim/${ASDF_INSTALL_VERSION}" 55 | export ASDF_NIM_DOWNLOAD_PATH 56 | ASDF_NIM_DOWNLOAD_PATH="${ASDF_NIM_TEMP}/download" # Temporary directory where downloads are placed 57 | export ASDF_NIM_INSTALL_PATH 58 | ASDF_NIM_INSTALL_PATH="${ASDF_NIM_TEMP}/install" # Temporary directory where installation is prepared 59 | mkdir -p "$ASDF_NIM_TEMP" 60 | rm -f "$(asdf_nim_log)" 61 | fi 62 | 63 | if [ "$ASDF_NIM_DEBUG" = "yes" ]; then 64 | out 65 | out "# Environment:" 66 | out 67 | env | grep "^ASDF_" | sort | xargs printf "# %s\n" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" || true 68 | fi 69 | } 70 | 71 | asdf_nim_init_traps() { 72 | # Exit handlers 73 | trap 'ASDF_NIM_EXIT_STATUS=$?; asdf_nim_on_exit; exit $ASDF_NIM_EXIT_STATUS' EXIT 74 | trap 'trap - HUP; ASDF_NIM_SIGNAL=SIGHUP; kill -HUP $$' HUP 75 | trap 'trap - INT; ASDF_NIM_SIGNAL=SIGINT; kill -INT $$' INT 76 | trap 'trap - TERM; ASDF_NIM_SIGNAL=SIGTERM; kill -TERM $$' TERM 77 | } 78 | 79 | out() { 80 | # To screen 81 | if [ "$ASDF_NIM_SILENT" = "no" ]; then 82 | echo "$@" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 83 | fi 84 | } 85 | 86 | asdf_nim_on_exit() { 87 | asdf_nim_cleanup_asdf_install_path() { 88 | if [ -d "$ASDF_INSTALL_PATH" ]; then 89 | step_start "rm ${ASDF_INSTALL_PATH//${HOME}/\~} …" 90 | rm -rf "$ASDF_INSTALL_PATH" 91 | step_end "✓" 92 | fi 93 | } 94 | 95 | asdf_nim_cleanup_asdf_download_path() { 96 | if [ -d "$ASDF_DOWNLOAD_PATH" ]; then 97 | if [ "${1-}" = "force" ]; then 98 | # Force delete 99 | step_start "rm ${ASDF_DOWNLOAD_PATH//${HOME}/\~}" 100 | rm -rf "$ASDF_DOWNLOAD_PATH" 101 | step_end "✓" 102 | else 103 | # asdf will delete this folder depending on --keep-download or 104 | # always_keep_download flag, so respect that by not deleting here; 105 | # however, asdf uses `rm -r` instead of `rm -rf` which fails to delete 106 | # protected git objects. So we simply chmod the git objects so they 107 | # can be deleted if asdf decides to delete. 108 | step_start "chmod ${ASDF_DOWNLOAD_PATH//${HOME}/\~}" 109 | chmod -R 700 "$ASDF_DOWNLOAD_PATH" 110 | step_end "✓" 111 | fi 112 | fi 113 | } 114 | 115 | asdf_nim_cleanup_temp() { 116 | if [ -d "$ASDF_NIM_TEMP" ]; then 117 | if [ "$ASDF_NIM_REMOVE_TEMP" = "yes" ]; then 118 | step_start "rm ${ASDF_NIM_TEMP//${HOME}/\~}" 119 | rm -rf "$ASDF_NIM_TEMP" 120 | step_end "✓" 121 | else 122 | step_start "ASDF_NIM_REMOVE_TEMP=${ASDF_NIM_REMOVE_TEMP}, keeping temp dir ${ASDF_NIM_TEMP//${HOME}/\~}" 123 | step_end "✓" 124 | fi 125 | fi 126 | } 127 | 128 | case "$ASDF_NIM_ACTION" in 129 | download) 130 | # install gets called by asdf even after a failed download, so don't do 131 | # any cleanup here... *unless* ASDF_NIM_SIGNAL is set, in which case 132 | # install will not be called and ASDF_DOWNLOAD_PATH should be deleted 133 | # regardless of --keep-download/always_keep_download. 134 | case "${ASDF_NIM_SIGNAL-}" in 135 | SIG*) 136 | # cleanup everything 137 | asdf_nim_cleanup_asdf_install_path 138 | asdf_nim_cleanup_asdf_download_path force 139 | asdf_nim_cleanup_temp 140 | out 141 | ;; 142 | *) ;; 143 | esac 144 | ;; 145 | install) 146 | # actually do cleanup here 147 | case "$ASDF_NIM_EXIT_STATUS" in 148 | 0) 149 | # successful install, only clean up temp dir, make download path 150 | # removable. 151 | asdf_nim_cleanup_asdf_download_path 152 | asdf_nim_cleanup_temp 153 | out 154 | ;; 155 | *) 156 | # failure, dump log 157 | out 158 | out "😱 Exited with status ${ASDF_NIM_EXIT_STATUS}:" 159 | out 160 | cat "$(asdf_nim_log download)" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 161 | cat "$(asdf_nim_log install)" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 162 | # cleanup everything 163 | out 164 | asdf_nim_cleanup_asdf_install_path 165 | asdf_nim_cleanup_asdf_download_path 166 | asdf_nim_cleanup_temp 167 | out 168 | ;; 169 | esac 170 | ;; 171 | esac 172 | } 173 | 174 | # Log file path. Most command output gets redirected here. 175 | asdf_nim_log() { 176 | local path 177 | path="${ASDF_NIM_TEMP}/${1:-$ASDF_NIM_ACTION}.log" 178 | touch "$path" 179 | echo "$path" 180 | } 181 | 182 | STEP=0 183 | 184 | section_start() { 185 | STEP=0 186 | if [ "$ASDF_NIM_SILENT" = "no" ]; then 187 | printf "\n%s\n" "$1" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 188 | fi 189 | } 190 | 191 | step_start() { 192 | export STEP=$((STEP + 1)) 193 | if [ "$ASDF_NIM_SILENT" = "no" ]; then 194 | printf " %s. %s … " "$STEP" "$1" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 195 | fi 196 | } 197 | 198 | step_end() { 199 | if [ "$ASDF_NIM_SILENT" = "no" ]; then 200 | printf "%s\n" "$1" 1>&"$ASDF_NIM_STDOUT" 2>&"$ASDF_NIM_STDERR" 201 | fi 202 | } 203 | 204 | die() { 205 | if [ "$ASDF_NIM_SILENT" = "no" ]; then 206 | printf "\n💥 %s\n\n" "$1" 1>&"$ASDF_NIM_STDERR" 207 | fi 208 | } 209 | 210 | # Sort semantic version numbers. 211 | asdf_nim_sort_versions() { 212 | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort -V | sed 's/_$//' 213 | } 214 | 215 | # List all stable Nim versions (tagged releases at github.com/nim-lang/Nim). 216 | asdf_nim_list_all_versions() { 217 | git ls-remote --tags --refs "$SOURCE_REPO" | 218 | awk -v col=2 '{print $col}' | 219 | grep '^refs/tags/.*' | 220 | sed 's/^refs\/tags\///' | 221 | sed 's/^v//' | 222 | asdf_nim_sort_versions 223 | } 224 | 225 | asdf_nim_normalize_os() { 226 | local os 227 | os="$(echo "${ASDF_NIM_MOCK_OS_NAME:-$(uname)}" | tr '[:upper:]' '[:lower:]')" 228 | case "$os" in 229 | darwin) echo macos ;; 230 | mingw*) echo windows ;; # not actually supported by asdf? 231 | *) echo "$os" ;; 232 | esac 233 | } 234 | 235 | # Detect the platform's architecture, normalize it to one of the following, and 236 | # echo it: 237 | # - x86_64 238 | # - i686 239 | # - armv5 240 | # - armv6 241 | # - armv7 242 | # - aaarch64 (on Linux) 243 | # - arm64 (on macOS) 244 | # - powerpc64le 245 | asdf_nim_normalize_arch() { 246 | local arch arm_arch arch_version 247 | arch="${ASDF_NIM_MOCK_MACHINE_NAME:-$(uname -m)}" 248 | case "$arch" in 249 | x86_64 | x64 | amd64) 250 | if [ -n "$(command -v gcc)" ] || [ -n "${ASDF_NIM_MOCK_GCC_DEFINES-}" ]; then 251 | # Edge case: detect 386 container on amd64 kernel using __amd64 definition 252 | IS_AMD64="$(echo "${ASDF_NIM_MOCK_GCC_DEFINES:-$(gcc -dM -E - armv7 294 | # shellcheck disable=SC2001 295 | arm_arch="$(echo "$arch" | sed 's/^\(armv[0-9]\{1,\}\).*$/\1/')" 296 | fi 297 | fi 298 | echo "$arm_arch" 299 | ;; 300 | ppc64le | powerpc64le | ppc64el | powerpc64el) echo powerpc64le ;; 301 | *) echo "$arch" ;; 302 | esac 303 | } 304 | 305 | asdf_nim_pkg_mgr() { 306 | echo "${ASDF_NIM_MOCK_PKG_MGR:-$( 307 | (command -v brew >/dev/null 2>&1 && echo "brew") || 308 | (command -v apt-get >/dev/null 2>&1 && echo "apt-get") || 309 | (command -v apk >/dev/null 2>&1 && echo "apk") || 310 | (command -v pacman >/dev/null 2>&1 && echo "pacman") || 311 | (command -v dnf >/dev/null 2>&1 && echo "dnf") || 312 | echo "" 313 | )}" 314 | } 315 | 316 | # List dependencies of this plugin, as package names for use with the system 317 | # package manager. 318 | asdf_nim_list_deps() { 319 | case "$(asdf_nim_pkg_mgr)" in 320 | apt-get) 321 | echo xz-utils 322 | echo build-essential 323 | ;; 324 | apk) 325 | echo xz 326 | echo build-base 327 | ;; 328 | brew) echo xz ;; 329 | *) 330 | case "$(asdf_nim_normalize_os)" in 331 | *) 332 | echo xz 333 | echo gcc 334 | ;; 335 | esac 336 | ;; 337 | esac 338 | } 339 | 340 | # Generate the command to install dependencies via the system package manager. 341 | asdf_nim_install_deps_cmds() { 342 | local deps 343 | deps="$(asdf_nim_list_deps | xargs)" 344 | case "$(asdf_nim_pkg_mgr)" in 345 | apt-get) echo "apt-get update -q -y && apt-get -qq install -y $deps" ;; 346 | apk) echo "apk add --update $deps" ;; 347 | brew) echo "brew install $deps" ;; 348 | pacman) echo "pacman -Syu --noconfirm $deps" ;; 349 | dnf) echo "dnf install -y $deps" ;; 350 | *) echo "" ;; 351 | esac 352 | } 353 | 354 | # Install missing dependencies using the system package manager. 355 | # Note - this is interactive, so in CI use `yes | cmd-that-calls-asdf_nim_install_deps`. 356 | asdf_nim_install_deps() { 357 | local deps 358 | deps="$(asdf_nim_list_deps | xargs)" 359 | local input 360 | input="" 361 | echo 362 | echo "[asdf-nim:install-deps] additional packages are required: ${deps}" 363 | echo 364 | if [ "${ASDF_NIM_INSTALL_DEPS_ACCEPT:-no}" = "no" ]; then 365 | read -r -p "[asdf-nim:install-deps] Install them now? [Y/n] " input 366 | else 367 | echo "[asdf-nim:install-deps] --yes passed, installing…" 368 | input="yes" 369 | fi 370 | echo 371 | 372 | case "$input" in 373 | [yY][eE][sS] | [yY] | "") 374 | local cmds 375 | cmds="$(asdf_nim_install_deps_cmds)" 376 | if [ -z "$cmds" ]; then 377 | echo 378 | echo "[asdf-nim:install-deps] no package managers recognized, install the packages manually." 379 | echo 380 | return 1 381 | else 382 | eval "$cmds" 383 | echo 384 | echo "[asdf-nim:install-deps] installed: ${deps}" 385 | echo 386 | fi 387 | ;; 388 | *) 389 | echo 390 | echo "[asdf-nim:install-deps] plugin will not function without: ${deps}" 391 | echo 392 | return 1 393 | ;; 394 | esac 395 | echo 396 | } 397 | 398 | # Detect if the standard C library on the system is musl or not. 399 | # Echoes "yes" or "no" 400 | asdf_nim_is_musl() { 401 | if [ -n "${ASDF_NIM_MOCK_IS_MUSL-}" ]; then 402 | echo "$ASDF_NIM_MOCK_IS_MUSL" 403 | else 404 | if [ -n "$(command -v ldd)" ]; then 405 | if (ldd --version 2>&1 || true) | grep -qF "musl"; then 406 | echo "yes" 407 | else 408 | echo "no" 409 | fi 410 | else 411 | echo "no" 412 | fi 413 | fi 414 | } 415 | 416 | # Echo the official binary archive URL (from nim-lang.org) for the current 417 | # architecture. 418 | asdf_nim_official_archive_url() { 419 | if [ "${ASDF_INSTALL_TYPE}" = "version" ] && [[ ${ASDF_INSTALL_VERSION} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 420 | case "$(asdf_nim_normalize_os)" in 421 | linux) 422 | case "$(asdf_nim_is_musl)" in 423 | no) 424 | # Official Linux builds are only available for glibc x86_64 and x86 425 | case "$(asdf_nim_normalize_arch)" in 426 | x86_64) echo "${LINUX_X64_URL//VERSION/$ASDF_INSTALL_VERSION}" ;; 427 | i686) echo "${LINUX_X32_URL//VERSION/$ASDF_INSTALL_VERSION}" ;; 428 | esac 429 | ;; 430 | esac 431 | ;; 432 | esac 433 | fi 434 | } 435 | 436 | # Echo the nightly url for arch/os 437 | asdf_nim_nightly_url() { 438 | if [ "${ASDF_INSTALL_TYPE}" != "ref" ]; then 439 | return 0 440 | fi 441 | if [[ $ASDF_INSTALL_VERSION =~ ^version-[0-9]+-[0-9]+$ ]] || [ "$ASDF_INSTALL_VERSION" = "devel" ]; then 442 | case "$(asdf_nim_normalize_os)" in 443 | linux) 444 | case "$(asdf_nim_is_musl)" in 445 | no) 446 | # Nightly Linux builds are only available for glibc and a few archs 447 | case "$(asdf_nim_normalize_arch)" in 448 | x86_64) echo "${LINUX_X64_NIGHTLY_URL//BRANCH/$ASDF_INSTALL_VERSION}" ;; 449 | i686) echo "${LINUX_X32_NIGHTLY_URL//BRANCH/$ASDF_INSTALL_VERSION}" ;; 450 | aarch64) echo "${LINUX_ARM64_NIGHTLY_URL//BRANCH/$ASDF_INSTALL_VERSION}" ;; 451 | armv7) echo "${LINUX_ARMV7L_NIGHTLY_URL//BRANCH/$ASDF_INSTALL_VERSION}" ;; 452 | esac 453 | ;; 454 | esac 455 | ;; 456 | macos) 457 | case "$(asdf_nim_normalize_arch)" in 458 | # Nightly macos builds are only available for x86_64 459 | x86_64) echo "${MACOS_X64_NIGHTLY_URL//BRANCH/$ASDF_INSTALL_VERSION}" ;; 460 | esac 461 | ;; 462 | esac 463 | fi 464 | } 465 | 466 | asdf_nim_github_token() { 467 | echo "${GITHUB_TOKEN:-${GITHUB_API_TOKEN-}}" 468 | } 469 | 470 | # Echo the source archive URL (from nim-lang.org). 471 | asdf_nim_source_url() { 472 | if [ "${ASDF_INSTALL_TYPE}" = "version" ] && [[ ${ASDF_INSTALL_VERSION} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then 473 | echo "${SOURCE_URL//VERSION/$ASDF_INSTALL_VERSION}" 474 | fi 475 | } 476 | 477 | asdf_nim_needs_download() { 478 | # No download path 479 | if [ ! -d "$ASDF_DOWNLOAD_PATH" ]; then 480 | echo "yes" 481 | else 482 | echo "no" 483 | fi 484 | } 485 | 486 | asdf_nim_download_urls() { 487 | # Official binaries 488 | asdf_nim_official_archive_url 489 | # Nightly binaries 490 | asdf_nim_nightly_url 491 | # Fall back to building from source 492 | asdf_nim_source_url 493 | } 494 | 495 | asdf_nim_download_via_git() { 496 | step_start "git clone" 497 | rm -rf "$ASDF_NIM_DOWNLOAD_PATH" 498 | mkdir -p "$ASDF_NIM_DOWNLOAD_PATH" 499 | ( 500 | cd "$ASDF_NIM_DOWNLOAD_PATH" || exit 501 | git init 502 | git remote add origin "$SOURCE_REPO" 503 | git fetch origin "$ASDF_INSTALL_VERSION" --depth 1 504 | git reset --hard FETCH_HEAD 505 | chmod -R 700 . # For asdf cleanup 506 | ) 507 | step_end "✓" 508 | } 509 | 510 | asdf_nim_download_via_url() { 511 | local urls url archive_path archive_name archive_ext 512 | # shellcheck disable=SC2207 513 | urls=($(asdf_nim_download_urls)) 514 | url="" 515 | archive_path="" 516 | if [ "${#urls[@]}" -eq 0 ]; then 517 | return 1 518 | fi 519 | for i in "${!urls[@]}"; do 520 | url="${urls[$i]}" 521 | step_start "curl ${url}" 522 | archive_path="$(asdf_nim_fetch "$url")" 523 | if [ -n "$archive_path" ]; then 524 | step_end "✓" 525 | break 526 | else 527 | if [ "$((i + 1))" -ge "${#urls[@]}" ]; then 528 | step_end "failed, no more URLs to try" 529 | return 1 530 | else 531 | step_end "failed, trying another URL" 532 | fi 533 | fi 534 | done 535 | archive_name="$(basename "$url")" 536 | archive_ext="${archive_name##*.}" 537 | step_start "unzip" 538 | 539 | rm -rf "$ASDF_NIM_DOWNLOAD_PATH" 540 | mkdir -p "$ASDF_NIM_DOWNLOAD_PATH" 541 | 542 | case "$archive_ext" in 543 | xz) tar -xJf "${ASDF_NIM_TEMP}/${archive_name}" -C "$ASDF_NIM_DOWNLOAD_PATH" --strip-components=1 ;; 544 | *) 545 | unzip -q "${ASDF_NIM_TEMP}/${archive_name}" -d "$ASDF_NIM_DOWNLOAD_PATH" 546 | mv -v "$ASDF_NIM_DOWNLOAD_PATH/nim-${ASDF_INSTALL_VERSION}/"* "$ASDF_NIM_DOWNLOAD_PATH" 547 | rm -vr "$ASDF_NIM_DOWNLOAD_PATH/nim-${ASDF_INSTALL_VERSION}" 548 | ;; 549 | esac 550 | step_end "✓" 551 | } 552 | 553 | # Detect which method to install Nim with (official binary, nightly binary, or 554 | # build from source), download the code to ASDF_NIM_DOWNLOAD_PATH, prepare it for 555 | # use by the build or install functions, then move it to ASDF_DOWNLOAD_PATH. 556 | asdf_nim_download() { 557 | section_start "I. Download (${ASDF_NIM_DOWNLOAD_PATH//${HOME}/\~})" 558 | { 559 | 560 | if [ -f "${ASDF_DOWNLOAD_PATH}/install.sh" ] || [ -f "${ASDF_DOWNLOAD_PATH}/build.sh" ] || [ -f "${ASDF_DOWNLOAD_PATH}/build_all.sh" ]; then 561 | step_start "already downloaded" 562 | step_end "✓" 563 | return 0 564 | fi 565 | 566 | date +%s >"${ASDF_NIM_TEMP}/download.start" 567 | 568 | if [ "$ASDF_NIM_DEBUG" = "yes" ]; then 569 | set -x 570 | fi 571 | 572 | # ref install type is usually a git commit-ish 573 | # but if it one of the "version-X-Y" branches, 574 | # it may have a nightly build for the current arch/os 575 | # so first try to download via URL 576 | # but if none is available, fallback to git 577 | if ! asdf_nim_download_via_url; then 578 | if [ "${ASDF_INSTALL_TYPE}" = "ref" ]; then 579 | asdf_nim_download_via_git 580 | else 581 | die "No download method available for ${ASDF_INSTALL_TYPE} ${ASDF_INSTALL_VERSION}" 582 | return 1 583 | fi 584 | fi 585 | 586 | step_start "mv to ${ASDF_DOWNLOAD_PATH//${HOME}/\~}" 587 | rm -rf "$ASDF_DOWNLOAD_PATH" 588 | mkdir -p "$(dirname "$ASDF_DOWNLOAD_PATH")" 589 | mv -v "$ASDF_NIM_DOWNLOAD_PATH" "$ASDF_DOWNLOAD_PATH" 590 | step_end "✓" 591 | 592 | if [ "$ASDF_NIM_DEBUG" = "yes" ]; then 593 | set +x 594 | fi 595 | } 1>>"$(asdf_nim_log)" 2>>"$(asdf_nim_log)" 596 | } 597 | 598 | asdf_nim_fetch() { 599 | local url 600 | url="$1" 601 | declare -a curl_args 602 | curl_args=("-fsSL" "--connect-timeout" "10") 603 | 604 | # Use a github personal access token to avoid API rate limiting 605 | if [ -n "$(asdf_nim_github_token)" ]; then 606 | case "$url" in 607 | 'https://github.com/'*) 608 | curl_args+=("-H" "Authorization: token $(asdf_nim_github_token)") 609 | ;; 610 | esac 611 | fi 612 | 613 | local archive_name 614 | archive_name="$(basename "$url")" 615 | local archive_path 616 | archive_path="${ASDF_NIM_TEMP}/${archive_name}" 617 | 618 | curl_args+=("$url" "-o" "$archive_path") 619 | 620 | # shellcheck disable=SC2046 621 | eval curl $(printf ' "%s" ' "${curl_args[@]}") && echo "$archive_path" || echo "" 622 | } 623 | 624 | asdf_nim_bootstrap_nim() { 625 | cd "$ASDF_DOWNLOAD_PATH" || exit 626 | 627 | local nim 628 | nim="./bin/nim" 629 | if [ ! -f "$nim" ]; then 630 | if [ -f "build.sh" ]; then 631 | # source directory has build.sh to build koch, nim, and tools. 632 | step_start "./build.sh" 633 | sh build.sh 634 | step_end "✓" 635 | elif [ -f "build_all.sh" ]; then 636 | # source directory has build_all.sh to build koch, nim, and tools. 637 | step_start "./build_all.sh" 638 | sh build_all.sh 639 | step_end "✓" 640 | else 641 | step_start "nim already built" 642 | step_end "✓" 643 | fi 644 | else 645 | step_start "nim already built" 646 | step_end "✓" 647 | fi 648 | 649 | [ -f "$nim" ] # A nim executable must exist at this point to proceed 650 | [ -f "./koch" ] || asdf_nim_build_koch "$nim" 651 | [ -f "./bin/nim" ] || asdf_nim_build_nim 652 | } 653 | 654 | asdf_nim_build_koch() { 655 | local nim 656 | nim="$1" 657 | step_start "build koch" 658 | cd "$ASDF_DOWNLOAD_PATH" || exit 659 | # shellcheck disable=SC2046 660 | eval "$nim" c --skipParentCfg:on $(printf ' %q ' "${NIM_ARGS[@]}") koch 661 | step_end "✓" 662 | } 663 | 664 | asdf_nim_build_nim() { 665 | step_start "build nim" 666 | cd "$ASDF_DOWNLOAD_PATH" || exit 667 | # shellcheck disable=SC2046 668 | eval ./koch boot $(printf ' %q ' "${NIM_ARGS[@]}") 669 | step_end "✓" 670 | } 671 | 672 | asdf_nim_build_tools() { 673 | step_start "build tools" 674 | cd "$ASDF_DOWNLOAD_PATH" || exit 675 | # shellcheck disable=SC2046 676 | eval ./koch tools $(printf ' %q ' "${NIM_ARGS[@]}") 677 | step_end "✓" 678 | } 679 | 680 | asdf_nim_build_nimble() { 681 | step_start "build nimble" 682 | cd "$ASDF_DOWNLOAD_PATH" || exit 683 | # shellcheck disable=SC2046 684 | eval ./koch nimble $(printf ' %q ' "${NIM_ARGS[@]}") 685 | step_end "✓" 686 | } 687 | 688 | # Build Nim binaries in ASDF_NIM_DOWNLOAD_PATH. 689 | asdf_nim_build() { 690 | section_start "II. Build (${ASDF_DOWNLOAD_PATH//${HOME}/\~})" 691 | 692 | cd "$ASDF_DOWNLOAD_PATH" || exit 693 | local bootstrap 694 | bootstrap=n 695 | local build_tools 696 | build_tools=n 697 | local build_nimble 698 | build_nimble=n 699 | [ -f "./bin/nim" ] || bootstrap=y 700 | [ -f "./bin/nimgrep" ] || build_tools=y 701 | [ -f "./bin/nimble" ] || build_nimble=y 702 | 703 | if [ "$bootstrap" = "n" ] && [ "$build_tools" = "n" ] && [ "$build_nimble" = "n" ]; then 704 | step_start "already built" 705 | step_end "✓" 706 | return 0 707 | fi 708 | 709 | [ "$bootstrap" = "n" ] || asdf_nim_bootstrap_nim 710 | [ "$build_tools" = "n" ] || asdf_nim_build_tools 711 | [ "$build_nimble" = "n" ] || asdf_nim_build_nimble 712 | } 713 | 714 | asdf_nim_time() { 715 | local start 716 | start="$(cat "${ASDF_NIM_TEMP}/download.start" 2>/dev/null || true)" 717 | if [ -n "$start" ]; then 718 | local now 719 | now="$(date +%s)" 720 | local secs 721 | secs="$((now - start))" 722 | local mins 723 | mins="0" 724 | if [[ $secs -ge 60 ]]; then 725 | local time_mins 726 | time_mins="$(echo "scale=2; ${secs}/60" | bc)" 727 | mins="$(echo "${time_mins}" | cut -d'.' -f1)" 728 | secs="0.$(echo "${time_mins}" | cut -d'.' -f2)" 729 | secs="$(echo "${secs}"*60 | bc | awk '{print int($1+0.5)}')" 730 | fi 731 | echo " in ${mins}m${secs}s" 732 | fi 733 | } 734 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "devDependencies": { 3 | "bats": "^1.11.0", 4 | "bats-assert": "github:bats-core/bats-assert#b93143a", 5 | "bats-support": "^0.3.0" 6 | }, 7 | "scripts": { 8 | "test": "bats test --tap" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"] 4 | } 5 | -------------------------------------------------------------------------------- /scripts/ci-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # CI script to install golang and asdf. 4 | # Only used on Linux / non-x86 architectures. 5 | # This is used in the "install" stage of the run-on-arch-action GitHub workflow. 6 | 7 | set -uexo pipefail 8 | 9 | export DEBIAN_FRONTEND=noninteractive 10 | export LANG=C.UTF-8 11 | export LC_ALL=C.UTF-8 12 | export PATH="/root/go/bin:${PATH}" 13 | 14 | # Install basic dependencies 15 | apt-get update -q -y 16 | apt-get -qq install -y ca-certificates curl gnupg 17 | 18 | update-ca-certificates || true 19 | 20 | # Install apt-fast for faster package downloads 21 | cat >/etc/apt/sources.list.d/apt-fast.list </etc/apt/sources.list.d/debian-backports.sources <&3 73 | } 74 | 75 | @test "nimble_configuration__without_nimbledeps" { 76 | # Assert package index is placed in the correct location 77 | info "nimble refresh -y" 78 | get_lock git 79 | nimble refresh -y 80 | clear_lock git 81 | assert [ -f "${ASDF_NIM_VERSION_INSTALL_PATH}/nimble/packages_official.json" ] 82 | 83 | # Assert package installs to correct location 84 | info "nimble install -y nimjson@1.2.8" 85 | get_lock git 86 | nimble install -y nimjson@1.2.8 87 | clear_lock git 88 | assert [ -x "${ASDF_NIM_VERSION_INSTALL_PATH}/nimble/bin/nimjson" ] 89 | assert [ -f "${ASDF_NIM_VERSION_INSTALL_PATH}/nimble/pkgs/nimjson-1.2.8/nimjson.nimble" ] 90 | assert [ ! -x "./nimbledeps/bin/nimjson" ] 91 | assert [ ! -f "./nimbledeps/pkgs/nimjson-1.2.8/nimjson.nimble" ] 92 | 93 | # Assert that shim was created for package binary 94 | assert [ -f "${ASDF_DATA_DIR}/shims/nimjson" ] 95 | 96 | # Assert that correct nimjson is used 97 | assert [ -n "$(nimjson -v | grep ' version 1\.2\.8' || true)" ] 98 | 99 | # Assert that nim finds nimble packages 100 | echo "import nimjson" >"${ASDF_NIM_TEST_TEMP}/testnimble.nim" 101 | info "nim c -r \"${ASDF_NIM_TEST_TEMP}/testnimble.nim\"" 102 | nim c -r "${ASDF_NIM_TEST_TEMP}/testnimble.nim" 103 | } 104 | 105 | @test "nimble_configuration__with_nimbledeps" { 106 | rm -rf nimbledeps 107 | mkdir "./nimbledeps" 108 | 109 | # Assert package index is placed in the correct location 110 | info "nimble refresh" 111 | get_lock git 112 | nimble refresh -y 113 | clear_lock git 114 | assert [ -f "./nimbledeps/packages_official.json" ] 115 | 116 | # Assert package installs to correct location 117 | info "nimble install -y nimjson@1.2.8" 118 | get_lock git 119 | nimble install -y nimjson@1.2.8 120 | clear_lock git 121 | assert [ -x "./nimbledeps/bin/nimjson" ] 122 | assert [ -f "./nimbledeps/pkgs/nimjson-1.2.8/nimjson.nimble" ] 123 | assert [ ! -x "${ASDF_NIM_VERSION_INSTALL_PATH}/nimble/bin/nimjson" ] 124 | assert [ ! -f "${ASDF_NIM_VERSION_INSTALL_PATH}/nimble/pkgs/nimjson-1.2.8/nimjson.nimble" ] 125 | 126 | # Assert that nim finds nimble packages 127 | echo "import nimjson" >"${ASDF_NIM_TEST_TEMP}/testnimble.nim" 128 | info "nim c --nimblePath:./nimbledeps/pkgs -r \"${ASDF_NIM_TEST_TEMP}/testnimble.nim\"" 129 | nim c --nimblePath:./nimbledeps/pkgs -r "${ASDF_NIM_TEST_TEMP}/testnimble.nim" 130 | 131 | rm -rf nimbledeps 132 | } 133 | -------------------------------------------------------------------------------- /test/lib/test_utils.bash: -------------------------------------------------------------------------------- 1 | export PROJECT_DIR 2 | PROJECT_DIR="$(realpath "$(dirname "$BATS_TEST_DIRNAME")")" 3 | 4 | get_lock() { 5 | local lock_path 6 | mkdir -p "${PROJECT_DIR}/.tmp" 7 | lock_path="${PROJECT_DIR}/.tmp/${1}.lock" 8 | # shellcheck disable=SC2188 9 | while ! { 10 | set -C 11 | 2>/dev/null >"$lock_path" 12 | }; do 13 | sleep 0.01 14 | done 15 | } 16 | 17 | clear_lock() { 18 | local lock_path 19 | mkdir -p "${PROJECT_DIR}/.tmp" 20 | lock_path="${PROJECT_DIR}/.tmp/${1}.lock" 21 | rm -f "$lock_path" 22 | } 23 | 24 | setup_test() { 25 | # Hide pretty output 26 | ASDF_NIM_SILENT="yes" 27 | export ASDF_NIM_SILENT 28 | 29 | ASDF_NIM_TEST_TEMP="$(mktemp -t asdf-nim-utils-tests.XXXX -d)" 30 | export ASDF_NIM_TEST_TEMP 31 | 32 | # Mock ASDF vars 33 | ASDF_DATA_DIR="${ASDF_NIM_TEST_TEMP}/asdf" 34 | export ASDF_DATA_DIR 35 | ASDF_INSTALL_VERSION="1.6.0" 36 | export ASDF_INSTALL_VERSION 37 | ASDF_INSTALL_TYPE="version" 38 | export ASDF_INSTALL_TYPE 39 | ASDF_INSTALL_PATH="${ASDF_DATA_DIR}/installs/nim/1.6.0" 40 | export ASDF_INSTALL_PATH 41 | ASDF_DOWNLOAD_PATH="${ASDF_DATA_DIR}/downloads/nim/1.6.0" 42 | export ASDF_DOWNLOAD_PATH 43 | ASDF_NIM_MOCK_GCC_DEFINES="#" 44 | export ASDF_NIM_MOCK_GCC_DEFINES 45 | 46 | # Mock some other vars 47 | export XDG_CONFIG_HOME 48 | XDG_CONFIG_HOME="$ASDF_NIM_TEST_TEMP" 49 | export ACTUAL_GITHUB_TOKEN 50 | ACTUAL_GITHUB_TOKEN="${GITHUB_TOKEN-}" 51 | export GITHUB_TOKEN 52 | GITHUB_TOKEN="" 53 | export GITHUB_USER 54 | GITHUB_USER="" 55 | export GITHUB_PASSWORD 56 | GITHUB_PASSWORD="" 57 | 58 | # Make plugin files findable via ASDF_DATA_DIR 59 | mkdir -p "${ASDF_DATA_DIR}/plugins" 60 | ln -s "$PROJECT_DIR" "${ASDF_DATA_DIR}/plugins/nim" 61 | } 62 | 63 | teardown_test() { 64 | rm -rf "$ASDF_NIM_TEST_TEMP" 65 | } 66 | -------------------------------------------------------------------------------- /test/utils.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | # shellcheck disable=SC2030,SC2031,SC2034,SC2230,SC2190 4 | 5 | load ../node_modules/bats-support/load.bash 6 | load ../node_modules/bats-assert/load.bash 7 | load ../lib/utils 8 | load ./lib/test_utils 9 | 10 | setup_file() { 11 | PROJECT_DIR="$(realpath "$(dirname "$BATS_TEST_DIRNAME")")" 12 | export PROJECT_DIR 13 | cd "$PROJECT_DIR" || exit 14 | clear_lock git 15 | } 16 | 17 | teardown_file() { 18 | clear_lock git 19 | } 20 | 21 | setup() { 22 | setup_test 23 | } 24 | 25 | teardown() { 26 | teardown_test 27 | } 28 | 29 | @test "asdf_nim_log__install" { 30 | asdf_nim_init "install" 31 | assert [ "$(asdf_nim_log)" = "${ASDF_DATA_DIR}/tmp/nim/1.6.0/install.log" ] 32 | } 33 | 34 | @test "asdf_nim_log__download" { 35 | asdf_nim_init "download" 36 | assert [ "$(asdf_nim_log)" = "${ASDF_DATA_DIR}/tmp/nim/1.6.0/download.log" ] 37 | } 38 | 39 | @test "asdf_nim_init__defaults" { 40 | unset ASDF_NIM_SILENT 41 | asdf_nim_init "download" 42 | 43 | # Configurable 44 | assert_equal "$ASDF_NIM_ACTION" "download" 45 | assert_equal "$ASDF_NIM_REMOVE_TEMP" "yes" 46 | assert_equal "$ASDF_NIM_DEBUG" "no" 47 | assert_equal "$ASDF_NIM_SILENT" "no" 48 | 49 | # Non-configurable 50 | assert_equal "$ASDF_NIM_TEMP" "${ASDF_DATA_DIR}/tmp/nim/1.6.0" 51 | assert_equal "$ASDF_NIM_DOWNLOAD_PATH" "${ASDF_NIM_TEMP}/download" 52 | assert_equal "$ASDF_NIM_INSTALL_PATH" "${ASDF_NIM_TEMP}/install" 53 | } 54 | 55 | @test "asdf_nim_init__configuration" { 56 | ASDF_NIM_REMOVE_TEMP="no" 57 | ASDF_NIM_DEBUG="yes" 58 | ASDF_NIM_SILENT="yes" 59 | ASDF_NIM_TEMP="${ASDF_NIM_TEST_TEMP}/configured" 60 | 61 | asdf_nim_init "install" 62 | 63 | # Configurable 64 | assert_equal "$ASDF_NIM_ACTION" "install" 65 | assert_equal "$ASDF_NIM_REMOVE_TEMP" "no" 66 | assert_equal "$ASDF_NIM_DEBUG" "yes" 67 | assert_equal "$ASDF_NIM_SILENT" "yes" 68 | 69 | # Non-configurable 70 | assert_equal "$ASDF_NIM_TEMP" "${ASDF_DATA_DIR}/tmp/nim/1.6.0" 71 | assert_equal "$ASDF_NIM_DOWNLOAD_PATH" "${ASDF_NIM_TEMP}/download" 72 | assert_equal "$ASDF_NIM_INSTALL_PATH" "${ASDF_NIM_TEMP}/install" 73 | } 74 | 75 | @test "asdf_nim_cleanup" { 76 | original="$ASDF_NIM_TEMP" 77 | run asdf_nim_init && 78 | asdf_nim_cleanup && 79 | [ -z "$ASDF_NIM_TEMP" ] && 80 | [ ! -d "$original" ] && 81 | [ "$ASDF_NIM_INITIALIZED" = "no" ] 82 | assert_success 83 | # TODO ASDF_NIM_STDOUT/ASDF_NIM_STDERR redirection test 84 | } 85 | 86 | @test "asdf_nim_sort_versions" { 87 | expected="0.2.2 1.1.1 1.2.0 1.6.0" 88 | output="$(printf "1.6.0\n0.2.2\n1.1.1\n1.2.0" | asdf_nim_sort_versions | xargs)" 89 | assert_equal "$output" "$expected" 90 | } 91 | 92 | @test "asdf_nim_list_all_versions__contains_tagged_releases" { 93 | run asdf_nim_list_all_versions 94 | 95 | # Can't hardcode the ever-growing list of releases, so just check for a few known ones 96 | assert_line 0.10.2 97 | assert_line 0.11.0 98 | assert_line 0.11.2 99 | assert_line 0.12.0 100 | assert_line 0.13.0 101 | assert_line 0.14.0 102 | assert_line 0.14.2 103 | assert_line 0.15.0 104 | assert_line 0.15.2 105 | assert_line 0.16.0 106 | assert_line 0.17.0 107 | assert_line 0.17.2 108 | assert_line 0.18.0 109 | assert_line 0.19.0 110 | assert_line 0.19.2 111 | assert_line 0.19.4 112 | assert_line 0.19.6 113 | assert_line 0.20.0 114 | assert_line 0.20.2 115 | assert_line 0.8.14 116 | assert_line 0.9.0 117 | assert_line 0.9.2 118 | assert_line 0.9.4 119 | assert_line 0.9.6 120 | assert_line 1.0.0 121 | assert_line 1.0.10 122 | assert_line 1.0.2 123 | assert_line 1.0.4 124 | assert_line 1.0.6 125 | assert_line 1.0.8 126 | assert_line 1.2.0 127 | assert_line 1.2.2 128 | assert_line 1.2.4 129 | assert_line 1.2.6 130 | assert_line 1.2.8 131 | assert_line 1.4.0 132 | assert_line 1.6.0 133 | assert_line 2.2.0 134 | } 135 | 136 | @test "asdf_nim_list_all_versions__displays_in_order" { 137 | assert [ "$(asdf_nim_list_all_versions | grep -Fn '1.6.0' | sed 's/:.*//' | head -n1)" -gt "$(asdf_nim_list_all_versions | grep -Fn '1.4.8' | sed 's/:.*//' | head -n1)" ] 138 | assert [ "$(asdf_nim_list_all_versions | grep -Fn '1.6.2' | sed 's/:.*//' | head -n1)" -gt "$(asdf_nim_list_all_versions | grep -Fn '1.6.0' | sed 's/:.*//' | head -n1)" ] 139 | assert [ "$(asdf_nim_list_all_versions | grep -Fn '1.6.4' | sed 's/:.*//' | head -n1)" -gt "$(asdf_nim_list_all_versions | grep -Fn '1.6.2' | sed 's/:.*//' | head -n1)" ] 140 | assert [ "$(asdf_nim_list_all_versions | grep -Fn '1.6.6' | sed 's/:.*//' | head -n1)" -gt "$(asdf_nim_list_all_versions | grep -Fn '1.6.4' | sed 's/:.*//' | head -n1)" ] 141 | assert [ "$(asdf_nim_list_all_versions | grep -Fn '1.6.8' | sed 's/:.*//' | head -n1)" -gt "$(asdf_nim_list_all_versions | grep -Fn '1.6.6' | sed 's/:.*//' | head -n1)" ] 142 | } 143 | 144 | @test "asdf_nim_normalize_os" { 145 | mkdir -p "${ASDF_NIM_TEST_TEMP}/bin" 146 | declare -A uname_outputs=( 147 | ["Darwin"]="macos" 148 | ["Linux"]="linux" 149 | ["MINGW"]="windows" # not actually supported by asdf? 150 | ["Unknown"]="unknown" 151 | ) 152 | for uname_output in "${!uname_outputs[@]}"; do 153 | # mock uname 154 | ASDF_NIM_MOCK_OS_NAME="${uname_output}" 155 | expected_os="${uname_outputs[$uname_output]}" 156 | output="$(asdf_nim_normalize_os)" 157 | assert_equal "$output" "$expected_os" 158 | done 159 | } 160 | 161 | @test "asdf_nim_normalize_arch__basic" { 162 | declare -A machine_names=( 163 | ["i386"]="i686" 164 | ["i486"]="i686" 165 | ["i586"]="i686" 166 | ["i686"]="i686" 167 | ["x86"]="i686" 168 | ["x32"]="i686" 169 | 170 | ["ppc64le"]="powerpc64le" 171 | ["unknown"]="unknown" 172 | ) 173 | 174 | for machine_name in "${!machine_name[@]}"; do 175 | # mock uname 176 | ASDF_NIM_MOCK_MACHINE_NAME="$machine_name" 177 | expected_arch="${machine_names[$machine_name]}" 178 | output="$(asdf_nim_normalize_arch)" 179 | assert_equal "$output" "$expected_arch" 180 | done 181 | } 182 | 183 | @test "asdf_nim_normalize_arch__i686__x86_64_docker" { 184 | # In x86_64 docker hosts running x86 containers, 185 | # the kernel uname will show x86_64 so we have to properly detect using the 186 | # __amd64 gcc define. 187 | 188 | # Expect i686 when __amd64 is not defined 189 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 190 | expected_arch="i686" 191 | output="$(asdf_nim_normalize_arch)" 192 | assert_equal "$output" "$expected_arch" 193 | 194 | ASDF_NIM_MOCK_MACHINE_NAME="amd64" 195 | expected_arch="i686" 196 | output="$(asdf_nim_normalize_arch)" 197 | assert_equal "$output" "$expected_arch" 198 | 199 | ASDF_NIM_MOCK_MACHINE_NAME="x64" 200 | expected_arch="i686" 201 | output="$(asdf_nim_normalize_arch)" 202 | assert_equal "$output" "$expected_arch" 203 | 204 | # Expect x86_64 only when __amd64 is defined 205 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 206 | 207 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 208 | expected_arch="x86_64" 209 | output="$(asdf_nim_normalize_arch)" 210 | assert_equal "$output" "$expected_arch" 211 | 212 | ASDF_NIM_MOCK_MACHINE_NAME="amd64" 213 | expected_arch="x86_64" 214 | output="$(asdf_nim_normalize_arch)" 215 | assert_equal "$output" "$expected_arch" 216 | 217 | ASDF_NIM_MOCK_MACHINE_NAME="x64" 218 | expected_arch="x86_64" 219 | output="$(asdf_nim_normalize_arch)" 220 | assert_equal "$output" "$expected_arch" 221 | } 222 | 223 | @test "asdf_nim_normalize_arch__arm32__via_gcc" { 224 | ASDF_NIM_MOCK_MACHINE_NAME="arm" 225 | for arm_version in {5..7}; do 226 | ASDF_NIM_MOCK_GCC_DEFINES="#define __ARM_ARCH ${arm_version}" 227 | expected_arch="armv${arm_version}" 228 | output="$(asdf_nim_normalize_arch)" 229 | assert_equal "$output" "$expected_arch" 230 | done 231 | } 232 | 233 | @test "asdf_nim_normalize_arch__armel__via_dpkg" { 234 | ASDF_NIM_MOCK_MACHINE_NAME="arm" 235 | ASDF_NIM_MOCK_DPKG_ARCHITECTURE="armel" 236 | expected_arch="armv5" 237 | output="$(asdf_nim_normalize_arch)" 238 | assert_equal "$output" "$expected_arch" 239 | } 240 | 241 | @test "asdf_nim_normalize_arch__armhf__via_dpkg" { 242 | ASDF_NIM_MOCK_MACHINE_NAME="arm" 243 | ASDF_NIM_MOCK_DPKG_ARCHITECTURE="armhf" 244 | expected_arch="armv7" 245 | output="$(asdf_nim_normalize_arch)" 246 | assert_equal "$output" "$expected_arch" 247 | } 248 | 249 | @test "asdf_nim_normalize_arch__arm__no_dpkg_no_gcc" { 250 | ASDF_NIM_MOCK_MACHINE_NAME="arm" 251 | expected_arch="armv5" 252 | output="$(asdf_nim_normalize_arch)" 253 | assert_equal "$output" "$expected_arch" 254 | } 255 | 256 | @test "asdf_nim_normalize_arch__armv7l__no_dpkg_no_gcc" { 257 | ASDF_NIM_MOCK_MACHINE_NAME="armv7l" 258 | expected_arch="armv7" 259 | output="$(asdf_nim_normalize_arch)" 260 | assert_equal "$output" "$expected_arch" 261 | } 262 | 263 | @test "asdf_nim_normalize_arch__arm64" { 264 | ASDF_NIM_MOCK_MACHINE_NAME="arm64" 265 | ASDF_NIM_MOCK_OS_NAME="Darwin" 266 | expected_arch="arm64" 267 | output="$(asdf_nim_normalize_arch)" 268 | assert_equal "$output" "$expected_arch" 269 | 270 | ASDF_NIM_MOCK_OS_NAME="Linux" 271 | expected_arch="aarch64" 272 | output="$(asdf_nim_normalize_arch)" 273 | assert_equal "$output" "$expected_arch" 274 | 275 | ASDF_NIM_MOCK_MACHINE_NAME="aarch64" 276 | ASDF_NIM_MOCK_OS_NAME="Linux" 277 | expected_arch="aarch64" 278 | output="$(asdf_nim_normalize_arch)" 279 | assert_equal "$output" "$expected_arch" 280 | } 281 | 282 | @test "asdf_nim_pkg_mgr" { 283 | mkdir -p "${ASDF_NIM_TEST_TEMP}/bin" 284 | declare -a bin_names=( 285 | "brew" 286 | "apt-get" 287 | "apk" 288 | "pacman" 289 | "dnf" 290 | ) 291 | for bin_name in "${bin_names[@]}"; do 292 | # mock package manager 293 | touch "${ASDF_NIM_TEST_TEMP}/bin/${bin_name}" 294 | chmod +x "${ASDF_NIM_TEST_TEMP}/bin/${bin_name}" 295 | output="$(PATH="${ASDF_NIM_TEST_TEMP}/bin" asdf_nim_pkg_mgr)" 296 | rm "${ASDF_NIM_TEST_TEMP}/bin/${bin_name}" 297 | assert_equal "$output" "$bin_name" 298 | done 299 | } 300 | 301 | @test "asdf_nim_list_deps__apt_get" { 302 | ASDF_NIM_MOCK_PKG_MGR="apt-get" 303 | expected="xz-utils build-essential" 304 | output="$(asdf_nim_list_deps | xargs)" 305 | assert_equal "$output" "$expected" 306 | } 307 | 308 | @test "asdf_nim_list_deps__apk" { 309 | ASDF_NIM_MOCK_PKG_MGR="apk" 310 | expected="xz build-base" 311 | output="$(asdf_nim_list_deps | xargs)" 312 | assert_equal "$output" "$expected" 313 | } 314 | 315 | @test "asdf_nim_list_deps__brew" { 316 | ASDF_NIM_MOCK_PKG_MGR="brew" 317 | expected="xz" 318 | output="$(asdf_nim_list_deps | xargs)" 319 | assert_equal "$output" "$expected" 320 | } 321 | 322 | @test "asdf_nim_list_deps__pacman" { 323 | ASDF_NIM_MOCK_PKG_MGR="pacman" 324 | expected="xz gcc" 325 | output="$(asdf_nim_list_deps | xargs)" 326 | assert_equal "$output" "$expected" 327 | } 328 | 329 | @test "asdf_nim_list_deps__dnf" { 330 | ASDF_NIM_MOCK_PKG_MGR="dnf" 331 | expected="xz gcc" 332 | output="$(asdf_nim_list_deps | xargs)" 333 | assert_equal "$output" "$expected" 334 | } 335 | 336 | @test "asdf_nim_install_deps_cmds__apt_get" { 337 | ASDF_NIM_MOCK_PKG_MGR="apt-get" 338 | expected="apt-get update -q -y && apt-get -qq install -y xz-utils build-essential" 339 | output="$(asdf_nim_install_deps_cmds)" 340 | assert_equal "$output" "$expected" 341 | } 342 | 343 | @test "asdf_nim_install_deps_cmds__apk" { 344 | ASDF_NIM_MOCK_PKG_MGR="apk" 345 | expected="apk add --update xz build-base" 346 | output="$(asdf_nim_install_deps_cmds)" 347 | assert_equal "$output" "$expected" 348 | } 349 | 350 | @test "asdf_nim_install_deps_cmds__brew" { 351 | ASDF_NIM_MOCK_PKG_MGR="brew" 352 | expected="brew install xz" 353 | output="$(asdf_nim_install_deps_cmds)" 354 | assert_equal "$output" "$expected" 355 | } 356 | 357 | @test "asdf_nim_install_deps_cmds__pacman" { 358 | ASDF_NIM_MOCK_PKG_MGR="pacman" 359 | expected="pacman -Syu --noconfirm xz gcc" 360 | output="$(asdf_nim_install_deps_cmds)" 361 | assert_equal "$output" "$expected" 362 | } 363 | 364 | @test "asdf_nim_install_deps_cmds__dnf" { 365 | ASDF_NIM_MOCK_PKG_MGR="dnf" 366 | expected="dnf install -y xz gcc" 367 | output="$(asdf_nim_install_deps_cmds)" 368 | assert_equal "$output" "$expected" 369 | } 370 | 371 | @test "asdf_nim_download_urls__stable__linux__x86_64__glibc" { 372 | ASDF_NIM_MOCK_OS_NAME="Linux" 373 | ASDF_NIM_MOCK_IS_MUSL="no" 374 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 375 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 376 | asdf_nim_init "install" 377 | expected="https://nim-lang.org/download/nim-1.6.0-linux_x64.tar.xz https://nim-lang.org/download/nim-1.6.0.tar.xz" 378 | output="$(asdf_nim_download_urls | xargs)" 379 | assert_equal "$output" "$expected" 380 | } 381 | 382 | @test "asdf_nim_download_urls__stable__linux__i686__glibc" { 383 | ASDF_NIM_MOCK_OS_NAME="Linux" 384 | ASDF_NIM_MOCK_IS_MUSL="no" 385 | ASDF_NIM_MOCK_MACHINE_NAME="i686" 386 | asdf_nim_init "install" 387 | expected="https://nim-lang.org/download/nim-1.6.0-linux_x32.tar.xz https://nim-lang.org/download/nim-1.6.0.tar.xz" 388 | output="$(asdf_nim_download_urls | xargs)" 389 | assert_equal "$output" "$expected" 390 | } 391 | 392 | @test "asdf_nim_download_urls__stable__linux__other_archs__glibc" { 393 | ASDF_NIM_MOCK_OS_NAME="Linux" 394 | ASDF_NIM_MOCK_IS_MUSL="no" 395 | declare -a machine_names=( 396 | "aarch64" 397 | "armv5" 398 | "armv6" 399 | "armv7" 400 | "powerpc64le" 401 | ) 402 | for machine_name in "${machine_names[@]}"; do 403 | ASDF_NIM_MOCK_MACHINE_NAME="$machine_name" 404 | asdf_nim_init "install" 405 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 406 | output="$(asdf_nim_download_urls | xargs)" 407 | assert_equal "$output" "$expected" 408 | done 409 | } 410 | 411 | @test "asdf_nim_download_urls__stable__linux__x86_64__musl" { 412 | ASDF_NIM_MOCK_OS_NAME="Linux" 413 | ASDF_NIM_MOCK_IS_MUSL="yes" 414 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 415 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 416 | asdf_nim_init "install" 417 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 418 | output="$(asdf_nim_download_urls | xargs)" 419 | assert_equal "$output" "$expected" 420 | } 421 | 422 | @test "asdf_nim_download_urls__stable__linux__other_archs__musl" { 423 | ASDF_NIM_MOCK_OS_NAME="Linux" 424 | ASDF_NIM_MOCK_IS_MUSL="yes" 425 | declare -a machine_names=( 426 | "aarch64" 427 | "armv5" 428 | "armv6" 429 | "armv7" 430 | "i686" 431 | "powerpc64le" 432 | ) 433 | for machine_name in "${machine_names[@]}"; do 434 | ASDF_NIM_MOCK_MACHINE_NAME="$machine_name" 435 | asdf_nim_init "install" 436 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 437 | output="$(asdf_nim_download_urls | xargs)" 438 | assert_equal "$output" "$expected" 439 | done 440 | } 441 | 442 | @test "asdf_nim_download_urls__stable__macos__x86_64" { 443 | ASDF_NIM_MOCK_OS_NAME="Darwin" 444 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 445 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 446 | asdf_nim_init "install" 447 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 448 | output="$(asdf_nim_download_urls | xargs)" 449 | assert_equal "$output" "$expected" 450 | } 451 | 452 | @test "asdf_nim_download_urls__stable__macos__arm64" { 453 | ASDF_NIM_MOCK_OS_NAME="Darwin" 454 | ASDF_NIM_MOCK_MACHINE_NAME="arm64" 455 | asdf_nim_init "install" 456 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 457 | output="$(asdf_nim_download_urls | xargs)" 458 | assert_equal "$output" "$expected" 459 | } 460 | 461 | @test "asdf_nim_download_urls__stable__netbsd__x86_64" { 462 | ASDF_NIM_MOCK_OS_NAME="NetBSD" 463 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 464 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 465 | asdf_nim_init "install" 466 | expected="https://nim-lang.org/download/nim-1.6.0.tar.xz" 467 | output="$(asdf_nim_download_urls | xargs)" 468 | assert_equal "$output" "$expected" 469 | } 470 | 471 | @test "asdf_nim_download_urls__nightly__linux__x86_64__musl" { 472 | ASDF_NIM_MOCK_OS_NAME="Linux" 473 | ASDF_NIM_MOCK_IS_MUSL="yes" 474 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 475 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 476 | ASDF_INSTALL_TYPE="ref" 477 | ASDF_INSTALL_VERSION="version-1-6" 478 | asdf_nim_init "install" 479 | expected="" 480 | output="$(asdf_nim_download_urls | xargs)" 481 | assert_equal "$output" "$expected" 482 | } 483 | 484 | @test "asdf_nim_download_urls__nightly__linux__other_archs__musl" { 485 | ASDF_NIM_MOCK_OS_NAME="Linux" 486 | ASDF_NIM_MOCK_IS_MUSL="yes" 487 | ASDF_INSTALL_TYPE="ref" 488 | ASDF_INSTALL_VERSION="version-1-6" 489 | declare -a machine_names=( 490 | "aarch64" 491 | "armv5" 492 | "armv6" 493 | "armv7" 494 | "i686" 495 | "powerpc64le" 496 | ) 497 | for machine_name in "${machine_names[@]}"; do 498 | ASDF_NIM_MOCK_MACHINE_NAME="$machine_name" 499 | asdf_nim_init "install" 500 | expected="" 501 | output="$(asdf_nim_download_urls | xargs)" 502 | assert_equal "$output" "$expected" 503 | done 504 | } 505 | 506 | @test "asdf_nim_download_urls__nightly__linux__x86_64__glibc" { 507 | ASDF_NIM_MOCK_OS_NAME="Linux" 508 | ASDF_NIM_MOCK_IS_MUSL="no" 509 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 510 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 511 | ASDF_INSTALL_TYPE="ref" 512 | ASDF_INSTALL_VERSION="version-1-6" 513 | asdf_nim_init "install" 514 | expected="https://github.com/nim-lang/nightlies/releases/download/latest-version-1-6/linux_x64.tar.xz" 515 | output="$(asdf_nim_download_urls | xargs)" 516 | assert_equal "$output" "$expected" 517 | } 518 | 519 | @test "asdf_nim_download_urls__nightly__linux__i686__glibc" { 520 | ASDF_NIM_MOCK_OS_NAME="Linux" 521 | ASDF_NIM_MOCK_IS_MUSL="no" 522 | ASDF_NIM_MOCK_MACHINE_NAME="i686" 523 | ASDF_INSTALL_TYPE="ref" 524 | ASDF_INSTALL_VERSION="version-1-6" 525 | asdf_nim_init "install" 526 | expected="https://github.com/nim-lang/nightlies/releases/download/latest-version-1-6/linux_x32.tar.xz" 527 | output="$(asdf_nim_download_urls | xargs)" 528 | assert_equal "$output" "$expected" 529 | } 530 | 531 | @test "asdf_nim_download_urls__nightly__linux__other_archs__glibc" { 532 | ASDF_NIM_MOCK_OS_NAME="Linux" 533 | ASDF_NIM_MOCK_IS_MUSL="no" 534 | ASDF_INSTALL_TYPE="ref" 535 | ASDF_INSTALL_VERSION="version-1-6" 536 | declare -a machine_names=( 537 | "armv5" 538 | "armv6" 539 | "powerpc64le" 540 | ) 541 | for machine_name in "${machine_names[@]}"; do 542 | ASDF_NIM_MOCK_MACHINE_NAME="$machine_name" 543 | asdf_nim_init "install" 544 | expected="" 545 | output="$(asdf_nim_download_urls | xargs)" 546 | assert_equal "$output" "$expected" 547 | done 548 | } 549 | 550 | @test "asdf_nim_download_urls__nightly__linux__armv7__glibc" { 551 | ASDF_NIM_MOCK_OS_NAME="Linux" 552 | ASDF_NIM_MOCK_MACHINE_NAME="armv7" 553 | ASDF_INSTALL_TYPE="ref" 554 | ASDF_INSTALL_VERSION="version-1-6" 555 | asdf_nim_init "install" 556 | expected="https://github.com/nim-lang/nightlies/releases/download/latest-version-1-6/linux_armv7l.tar.xz" 557 | output="$(asdf_nim_download_urls | xargs)" 558 | assert_equal "$output" "$expected" 559 | } 560 | 561 | @test "asdf_nim_download_urls__nightly__linux__aarch64__glibc" { 562 | ASDF_NIM_MOCK_OS_NAME="Linux" 563 | ASDF_NIM_MOCK_MACHINE_NAME="aarch64" 564 | ASDF_INSTALL_TYPE="ref" 565 | ASDF_INSTALL_VERSION="devel" 566 | asdf_nim_init "install" 567 | expected="https://github.com/nim-lang/nightlies/releases/download/latest-devel/linux_arm64.tar.xz" 568 | output="$(asdf_nim_download_urls | xargs)" 569 | assert_equal "$output" "$expected" 570 | } 571 | 572 | @test "asdf_nim_download_urls__nightly__macos__x86_64" { 573 | ASDF_NIM_MOCK_OS_NAME="Darwin" 574 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 575 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 576 | ASDF_INSTALL_TYPE="ref" 577 | ASDF_INSTALL_VERSION="version-1-6" 578 | asdf_nim_init "install" 579 | expected="https://github.com/nim-lang/nightlies/releases/download/latest-version-1-6/macosx_x64.tar.xz" 580 | output="$(asdf_nim_download_urls | xargs)" 581 | assert_equal "$output" "$expected" 582 | } 583 | 584 | @test "asdf_nim_download_urls__nightly__macos__arm64" { 585 | ASDF_NIM_MOCK_OS_NAME="Darwin" 586 | ASDF_NIM_MOCK_MACHINE_NAME="arm64" 587 | ASDF_INSTALL_TYPE="ref" 588 | ASDF_INSTALL_VERSION="version-1-6" 589 | asdf_nim_init "install" 590 | expected="" 591 | output="$(asdf_nim_download_urls | xargs)" 592 | assert_equal "$output" "$expected" 593 | } 594 | 595 | @test "asdf_nim_download_urls__nightly__netbsd__x86_64" { 596 | ASDF_NIM_MOCK_OS_NAME="NetBSD" 597 | ASDF_NIM_MOCK_MACHINE_NAME="x86_64" 598 | ASDF_NIM_MOCK_GCC_DEFINES="#define __amd64 1" 599 | ASDF_INSTALL_TYPE="ref" 600 | ASDF_INSTALL_VERSION="version-1-6" 601 | asdf_nim_init "install" 602 | expected="" 603 | output="$(asdf_nim_download_urls | xargs)" 604 | assert_equal "$output" "$expected" 605 | } 606 | 607 | @test "asdf_nim_needs_download__missing_ASDF_DOWNLOAD_PATH" { 608 | asdf_nim_init "install" 609 | run asdf_nim_needs_download 610 | assert_output "yes" 611 | } 612 | 613 | @test "asdf_nim_needs_download__with_ASDF_DOWNLOAD_PATH" { 614 | asdf_nim_init "install" 615 | mkdir -p "$ASDF_DOWNLOAD_PATH" 616 | run asdf_nim_needs_download 617 | assert_output "no" 618 | } 619 | 620 | @test "asdf_nim_download__ref" { 621 | export ASDF_INSTALL_TYPE 622 | ASDF_INSTALL_TYPE="ref" 623 | export ASDF_INSTALL_VERSION 624 | ASDF_INSTALL_VERSION="HEAD" 625 | asdf_nim_init "download" 626 | get_lock git 627 | run asdf_nim_download 628 | clear_lock git 629 | assert_success 630 | assert [ -d "${ASDF_DOWNLOAD_PATH}/.git" ] 631 | assert [ -f "${ASDF_DOWNLOAD_PATH}/koch.nim" ] 632 | } 633 | 634 | @test "asdf_nim_download__version" { 635 | ASDF_DOWNLOAD_PATH="${ASDF_DATA_DIR}/downloads/nim/${ASDF_INSTALL_VERSION}" 636 | asdf_nim_init "download" 637 | get_lock git 638 | run asdf_nim_download 639 | clear_lock git 640 | assert_success 641 | refute [ -d "${ASDF_DOWNLOAD_PATH}/.git" ] 642 | assert [ -f "${ASDF_DOWNLOAD_PATH}/koch.nim" ] 643 | } 644 | 645 | # @test "asdf_nim_build" { 646 | # skip "TODO, but covered by integration tests & CI" 647 | # } 648 | 649 | # @test "asdf_nim_install" { 650 | # skip "TODO, but covered by integration tests & CI" 651 | # } 652 | --------------------------------------------------------------------------------