diff --git a/.github/workflows/release-linux-arm.yml b/.github/workflows/release-linux-arm.yml deleted file mode 100644 index 143c546a..00000000 --- a/.github/workflows/release-linux-arm.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Release Linux ARM - -permissions: - contents: write - -on: - release: - types: [released] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Install dependencies - run: sudo apt-get update && sudo apt-get install -y pkg-config libssl-dev - - - name: Install cross - run: cargo install cross - - - name: Build with cross - run: cross build --release --target aarch64-unknown-linux-gnu - - - name: Create .tar.xz archive - run: tar -cJf amber-aarch64-unknown-linux-gnu.tar.xz -C ./resources . -C ../target/aarch64-unknown-linux-gnu/release amber - - - name: Upload Release Asset - uses: softprops/action-gh-release@v2 - with: - files: amber-aarch64-unknown-linux-gnu.tar.xz diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dddacada..3caac3d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,12 @@ +# This file was autogenerated by dist: https://opensource.axo.dev/cargo-dist/ +# # Copyright 2022-2024, axodotdev # SPDX-License-Identifier: MIT or Apache-2.0 # # CI that: # # * checks for a Git Tag that looks like a release -# * builds artifacts with cargo-dist (archives, installers, hashes) +# * builds artifacts with dist (archives, installers, hashes) # * uploads those artifacts to temporary workflow zip # * on success, uploads the artifacts to a GitHub Release # @@ -12,9 +14,8 @@ # title/body based on your changelogs. name: Release - permissions: - contents: write + "contents": "write" # This task will run whenever you push a git tag that looks like a version # like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc. @@ -23,10 +24,10 @@ permissions: # must be a Cargo-style SemVer Version (must have at least major.minor.patch). # # If PACKAGE_NAME is specified, then the announcement will be for that -# package (erroring out if it doesn't have the given version or isn't cargo-dist-able). +# package (erroring out if it doesn't have the given version or isn't dist-able). # # If PACKAGE_NAME isn't specified, then the announcement will be for all -# (cargo-dist-able) packages in the workspace with that version (this mode is +# (dist-able) packages in the workspace with that version (this mode is # intended for workspaces with only one dist-able package, or with all dist-able # packages versioned/released in lockstep). # @@ -43,9 +44,9 @@ on: - '**[0-9]+.[0-9]+.[0-9]+*' jobs: - # Run 'cargo dist plan' (or host) to determine what tasks we need to do + # Run 'dist plan' (or host) to determine what tasks we need to do plan: - runs-on: ubuntu-latest + runs-on: "ubuntu-20.04" outputs: val: ${{ steps.plan.outputs.manifest }} tag: ${{ !github.event.pull_request && github.ref_name || '' }} @@ -57,11 +58,16 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist + - name: Install dist # we specify bash to get pipefail; it guards against the `curl` command # failing. otherwise `sh` won't catch that `curl` returned non-0 shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh" + run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.27.0/cargo-dist-installer.sh | sh" + - name: Cache dist + uses: actions/upload-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/dist # sure would be cool if github gave us proper conditionals... # so here's a doubly-nested ternary-via-truthiness to try to provide the best possible # functionality based on whether this is a pull_request, and whether it's from a fork. @@ -69,8 +75,8 @@ jobs: # but also really annoying to build CI around when it needs secrets to work right.) - id: plan run: | - cargo dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json - echo "cargo dist ran successfully" + dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json + echo "dist ran successfully" cat plan-dist-manifest.json echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT" - name: "Upload dist-manifest.json" @@ -88,18 +94,19 @@ jobs: if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }} strategy: fail-fast: false - # Target platforms/runners are computed by cargo-dist in create-release. + # Target platforms/runners are computed by dist in create-release. # Each member of the matrix has the following arguments: # # - runner: the github runner - # - dist-args: cli flags to pass to cargo dist - # - install-dist: expression to run to install cargo-dist on the runner + # - dist-args: cli flags to pass to dist + # - install-dist: expression to run to install dist on the runner # # Typically there will be: # - 1 "global" task that builds universal installers # - N "local" tasks that build each platform's binaries and platform-specific installers matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }} runs-on: ${{ matrix.runner }} + container: ${{ matrix.container && matrix.container.image || null }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json @@ -110,11 +117,15 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - uses: swatinem/rust-cache@v2 - with: - key: ${{ join(matrix.targets, '-') }} - - name: Install cargo-dist - run: ${{ matrix.install_dist }} + - name: Install Rust non-interactively if not already installed + if: ${{ matrix.container }} + run: | + if ! command -v cargo > /dev/null 2>&1; then + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + echo "$HOME/.cargo/bin" >> $GITHUB_PATH + fi + - name: Install dist + run: ${{ matrix.install_dist.run }} # Get the dist-manifest - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -128,8 +139,8 @@ jobs: - name: Build artifacts run: | # Actually do builds and make zips and whatnot - cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json + echo "dist ran successfully" - id: cargo-dist name: Post-build # We force bash here just because github makes it really hard to get values up @@ -139,7 +150,7 @@ jobs: run: | # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" - jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" + dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -164,9 +175,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - shell: bash - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh" + - name: Install cached dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/dist # Get all the local artifacts for the global tasks to use (for e.g. checksums) - name: Fetch local artifacts uses: actions/download-artifact@v4 @@ -174,30 +188,15 @@ jobs: pattern: artifacts-* path: target/distrib/ merge-multiple: true - - name: Cargo Deb - run: | - cargo install cargo-deb - cargo deb --output="./target/distrib/amber-amd64.deb" - - name: Compile installer/uninstaller - run: | - TARGET_TRIPLE="$(rustc -Vv | awk '/^host/ { print $2 }')" - AMBER_PACKAGE="$PWD/target/distrib/amber-${TARGET_TRIPLE}" - tar -xf ${AMBER_PACKAGE}.tar.xz -C ./target - AMBER="$PWD/target/amber-${TARGET_TRIPLE}/amber" - $AMBER ./setup/install.ab ./target/distrib/install.sh - $AMBER ./setup/uninstall.ab ./target/distrib/uninstall.sh - id: cargo-dist shell: bash run: | - cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json - echo "cargo dist ran successfully" + dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json + echo "dist ran successfully" # Parse out what we just built and upload it to scratch storage echo "paths<> "$GITHUB_OUTPUT" jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT" - echo "$PWD/target/distrib/amber-amd64.deb" >> "$GITHUB_OUTPUT" - echo "$PWD/target/distrib/install.sh" >> "$GITHUB_OUTPUT" - echo "$PWD/target/distrib/uninstall.sh" >> "$GITHUB_OUTPUT" echo "EOF" >> "$GITHUB_OUTPUT" cp dist-manifest.json "$BUILD_MANIFEST_NAME" @@ -225,8 +224,12 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: Install cargo-dist - run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.14.1/cargo-dist-installer.sh | sh" + - name: Install cached dist + uses: actions/download-artifact@v4 + with: + name: cargo-dist-cache + path: ~/.cargo/bin/ + - run: chmod +x ~/.cargo/bin/dist # Fetch artifacts from scratch-storage - name: Fetch artifacts uses: actions/download-artifact@v4 @@ -234,11 +237,10 @@ jobs: pattern: artifacts-* path: target/distrib/ merge-multiple: true - # This is a harmless no-op for GitHub Releases, hosting for that happens in "announce" - id: host shell: bash run: | - cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json + dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json echo "artifacts uploaded and released successfully" cat dist-manifest.json echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT" @@ -248,8 +250,29 @@ jobs: # Overwrite the previous copy name: artifacts-dist-manifest path: dist-manifest.json + # Create a GitHub Release while uploading all files to it + - name: "Download GitHub Artifacts" + uses: actions/download-artifact@v4 + with: + pattern: artifacts-* + path: artifacts + merge-multiple: true + - name: Cleanup + run: | + # Remove the granular manifests + rm -f artifacts/*-dist-manifest.json + - name: Create GitHub Release + env: + PRERELEASE_FLAG: "${{ fromJson(steps.host.outputs.manifest).announcement_is_prerelease && '--prerelease' || '' }}" + ANNOUNCEMENT_TITLE: "${{ fromJson(steps.host.outputs.manifest).announcement_title }}" + ANNOUNCEMENT_BODY: "${{ fromJson(steps.host.outputs.manifest).announcement_github_body }}" + RELEASE_COMMIT: "${{ github.sha }}" + run: | + # Write and read notes from a file to avoid quoting breaking things + echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt + + gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/* - # Create a GitHub Release while uploading all files to it announce: needs: - plan @@ -265,23 +288,3 @@ jobs: - uses: actions/checkout@v4 with: submodules: recursive - - name: "Download GitHub Artifacts" - uses: actions/download-artifact@v4 - with: - pattern: artifacts-* - path: artifacts - merge-multiple: true - - name: Cleanup - run: | - # Remove the granular manifests - rm -f artifacts/*-dist-manifest.json - - name: Create GitHub Release - uses: ncipollo/release-action@v1 - with: - tag: ${{ needs.plan.outputs.tag }} - name: ${{ fromJson(needs.host.outputs.val).announcement_title }} - artifacts: "artifacts/*" - allowUpdates: true - prerelease: false - omitBody: true - omitBodyDuringUpdate: true diff --git a/.github/workflows/snap.yml b/.github/workflows/snap.yml deleted file mode 100644 index 013bed6b..00000000 --- a/.github/workflows/snap.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Build test Amber Snap -on: - push: - branches: - - master - workflow_dispatch: - -jobs: - snap: - name: Build snap - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: snapcore/action-build@v1 - id: snapcraft - - uses: actions/upload-artifact@v4 - if: ${{ github.event_name == 'release' }} #uploads the snap only if it's a release - with: - name: amber-snap - path: ${{ steps.snapcraft.outputs.snap }} diff --git a/Cargo.toml b/Cargo.toml index de76dc1d..e7fc22b1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,11 +7,6 @@ homepage = "https://amber-lang.com/" description = "The Programming Language compiled to Bash." rust-version = "1.79" -[package.metadata.deb] -maintainer = "Amber-Lang project" -license-file = "LICENSE.md" -copyright = "GPLv3" - # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] @@ -52,28 +47,5 @@ opt-level = 3 [workspace] members = ["meta"] -# Config for 'cargo dist' -[workspace.metadata.dist] -# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax) -cargo-dist-version = "0.14.1" -# CI backends to support -ci = "github" -# The installers to generate for each app -installers = [] -# Target platforms to build apps for (Rust target-triple syntax) -targets = [ - "aarch64-apple-darwin", - "x86_64-apple-darwin", - "x86_64-unknown-linux-gnu", - "x86_64-unknown-linux-musl", - "x86_64-pc-windows-msvc" -] -# Publish jobs to run in CI -pr-run-mode = "skip" -# Skip checking whether the specified configuration files are up to date -allow-dirty = ["ci"] -# Include std lib files in the dist -include = ["resources/std"] - [build-dependencies] build-helper = "0.1.1" diff --git a/dist-workspace.toml b/dist-workspace.toml new file mode 100644 index 00000000..36f99d23 --- /dev/null +++ b/dist-workspace.toml @@ -0,0 +1,23 @@ +[workspace] +members = ["cargo:."] + +# Config for 'dist' +[dist] +# The preferred dist version to use in CI (Cargo.toml SemVer syntax) +cargo-dist-version = "0.27.0" +# CI backends to support +ci = "github" +# The installers to generate for each app +installers = ["shell"] +# Target platforms to build apps for (Rust target-triple syntax) +targets = ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "aarch64-pc-windows-msvc", "x86_64-apple-darwin", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-pc-windows-msvc"] +# Skip checking whether the specified configuration files are up to date +allow-dirty = ["ci"] +# Path that installers should place binaries in +install-path = "CARGO_HOME" +# Whether to install an updater program +install-updater = true +# Extra static files to include in each App (path relative to this Cargo.toml's dir) +include = ["std", "assets"] +# Success installation message +custom-success-msg = "Amber has been installed successfully. 🎉\n> Now you can use amber by typing `amber` in your terminal." diff --git a/setup/install.ab b/setup/install.ab deleted file mode 100644 index 2d539d8d..00000000 --- a/setup/install.ab +++ /dev/null @@ -1,153 +0,0 @@ -import { has_failed, input_prompt } from "std/env" -import { split_chars } from "std/text" -import { array_contains } from "std/array" -import { file_exists } from "std/fs" -import { get_os, get_arch, get_target_folder, get_bins_folder } from "./shared.ab" - -let name = "amber" -let executable = "amber" -let archive = "amber.tar.xz" -let agent = has_failed("uname -a") - then "unknown" - else trust $ uname -a $ - -echo "" - -fun get_latest_release_tag() { - let tag_url = "https://api.github.com/repos/amber-lang/{name}/releases/latest" - let tag_json = $ curl -sL "{tag_url}" $? - // Get the tag name from the JSON - let tag = $ echo "\${nameof tag_json}" \ - | grep -Eo "tag_name\\"[^\\"]*\\"([^\\"]+)\\"" \ - | grep -Eo "\\"[^\\"]+\\"\$" \ - | grep -Eo "[^\\"\\s]+" $? - return tag -} - -main(args) { - let os = get_os() - let arch = get_arch() - - let user_only_install = array_contains(args, "--user") - let target_folder = get_target_folder(user_only_install) - let bins_folder = get_bins_folder(user_only_install) - - // Check if such directory exists - trust $ test -d "{target_folder}" $ - - if status == 0 { - echo "Amber already installed" - echo "It seems that Amber is already installed on your system. ({target_folder})" - echo "If you want to reinstall Amber, uninstall it first." - echo "(Find out more at https://docs.amber-lang.com/getting_started/installation#uninstallation)" - exit 2 - } - - // Check if curl is installed - if has_failed("curl -V") { - echo "Curl is not installed on your system." - echo "Please install `curl` and try again." - exit 1 - } - - echo "Installing Amber... 🚀" - - // Make the directories we need first to ensure we have permissions before downloading any files - // this decreases the chance that our script results in partial installation leaving assets behind - let sudo = user_only_install then "" else "sudo" - // Create directory for amber - silent $ {sudo} mkdir -p "{target_folder}" $ failed { - echo "Failed to create directory for amber." - if user_only_install { - echo "Please make sure that root user can access {target_folder} directory." - } else { - echo "Please make sure that your user can access {target_folder} directory." - } - exit 1 - } - if user_only_install { - silent $ mkdir -p "{bins_folder}" $ failed { - echo "Failed to create directory for amber bin at {bins_folder}." - exit 1 - } - } - - let tag = get_latest_release_tag() failed { - echo "Failed to get the latest release tag." - echo "Please try again or use another download method." - exit 1 - } - - // Set the download link - let url = "https://github.com/amber-lang/{name}/releases/download/{tag}/amber-{arch}-{os}.tar.xz" - - // Download amber - silent $ curl -L -o "{archive}" "{url}" $ failed { - echo "Curl failed to download amber." - echo "Something went wrong. Please try again later." - exit 1 - } - - // Move archived version of amber - $ {sudo} mv "{archive}" "{target_folder}/{archive}" $ failed { - echo "Failed to move amber to the installation directory." - echo "Please make sure that root user can access {target_folder} directory." - exit 1 - } - - // Unarchive amber - silent $ {sudo} tar --strip-components=1 -xvf {target_folder}/{archive} -C {target_folder} $ failed { - echo "Failed to unarchive amber at {target_folder}/{archive}" - echo "Please make sure that you have `tar` command installed." - exit 1 - } - - // Delete the archive - $ {sudo} rm {target_folder}/{archive} $ failed { - echo "Failed to remove downloaded archive at {target_folder}/{archive}" - exit 1 - } - - // Give permissions to execute amber - $ {sudo} chmod +x "{target_folder}/{executable}" $ failed { - echo "Failed to give permissions to execute amber." - echo "Please make sure that root user can access {target_folder} directory." - exit 1 - } - - // Delete the previous symbolic link - if file_exists("{bins_folder}/{executable}") { - $ {sudo} rm "{bins_folder}/{executable}" $ failed { - echo "Failed to remove the previous amber symbol link." - echo "Please make sure that root user can access {bins_folder} directory." - exit 1 - } - } - - // Create amber executable - $ {sudo} echo '#!/bin/bash\nexport STD_PATH="{target_folder}/std"\nexec {target_folder}/{executable} "\$@"' > {bins_folder}/{executable} $ failed { - echo "Failed to create amber executable." - echo "Please make sure that root user can access {bins_folder} directory." - exit 1 - } - - // Give permissions to execute amber - $ {sudo} chmod +x "{bins_folder}/{executable}" $ failed { - echo "Failed to give permissions to execute amber." - echo "Please make sure that root user can access {bins_folder} directory." - exit 1 - } - - let nickname = input_prompt("Would you like to help improve Amber by sharing your OS info with our developer database? Enter your GitHub nickname (or any nickname) or type `no`:") - if (nickname != "no") { - // Send feedback to the server - trust silent $ curl -G --data-urlencode "agent={agent}" --data-urlencode "nickname={nickname}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" $ - } - - // Send success message - echo "Amber has been installed successfully. 🎉" - echo "> Now you can use amber by typing `amber` in your terminal." - if user_only_install { - echo "> Since you requested a user only install with `--user` ensure that ~/.local/bin is in your \\$PATH." - } -} diff --git a/setup/install.sh b/setup/install.sh deleted file mode 100755 index fc25e989..00000000 --- a/setup/install.sh +++ /dev/null @@ -1,336 +0,0 @@ -#!/usr/bin/env bash -# Written in [Amber](https://amber-lang.com/) -# version: 0.3.5-alpha -# date: 2024-11-22 12:46:50 -file_exist__34_v0() { - local path=$1 - [ -f "${path}" ] - __AS=$? - if [ $__AS != 0 ]; then - __AF_file_exist34_v0=0 - return 0 - fi - __AF_file_exist34_v0=1 - return 0 -} -input__95_v0() { - local prompt=$1 - read -p "$prompt" - __AS=$? - __AF_input95_v0="$REPLY" - return 0 -} -has_failed__98_v0() { - local command=$1 - eval ${command} >/dev/null 2>&1 - __AS=$? - __AF_has_failed98_v0=$(echo $__AS '!=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') - return 0 -} -array_first_index__114_v0() { - local array=("${!1}") - local value=$2 - index=0 - for element in "${array[@]}"; do - if [ $( - [ "_${value}" != "_${element}" ] - echo $? - ) != 0 ]; then - __AF_array_first_index114_v0=${index} - return 0 - fi - ((index++)) || true - done - __AF_array_first_index114_v0=$(echo '-' 1 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') - return 0 -} -includes__116_v0() { - local array=("${!1}") - local value=$2 - array_first_index__114_v0 array[@] "${value}" - __AF_array_first_index114_v0__26_18="$__AF_array_first_index114_v0" - local result="$__AF_array_first_index114_v0__26_18" - __AF_includes116_v0=$(echo ${result} '>=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') - return 0 -} -get_os__121_v0() { - # Determine OS type - __AMBER_VAL_0=$(uname -s) - __AS=$? - if [ $__AS != 0 ]; then - echo "Failed to determine OS type (using \`uname\` command)." - echo "Please try again or make sure you have it installed." - exit 1 - fi - local os_type="${__AMBER_VAL_0}" - if [ $( - [ "_${os_type}" != "_Darwin" ] - echo $? - ) != 0 ]; then - __AF_get_os121_v0="apple-darwin" - return 0 - fi - if [ $( - [ "_${os_type}" == "_Linux" ] - echo $? - ) != 0 ]; then - echo "Unsupported OS type: ${os_type}" - echo "Please try again or use another download method." - exit 1 - fi - has_failed__98_v0 "ls -l /lib | grep libc.musl" - __AF_has_failed98_v0__20_12="$__AF_has_failed98_v0" - if [ $(echo '!' "$__AF_has_failed98_v0__20_12" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then - __AF_get_os121_v0="unknown-linux-musl" - return 0 - fi - __AF_get_os121_v0="unknown-linux-gnu" - return 0 -} -get_arch__122_v0() { - # Determine architecture - __AMBER_VAL_1=$(uname -m) - __AS=$? - if [ $__AS != 0 ]; then - echo "Failed to determine architecture." - echo "Please try again or use another download method." - exit 1 - fi - local arch_type="${__AMBER_VAL_1}" - __AMBER_ARRAY_0=("arm64" "aarch64") - includes__116_v0 __AMBER_ARRAY_0[@] "${arch_type}" - __AF_includes116_v0__34_16="$__AF_includes116_v0" - local arch=$(if [ "$__AF_includes116_v0__34_16" != 0 ]; then echo "aarch64"; else echo "x86_64"; fi) - __AF_get_arch122_v0="${arch}" - return 0 -} -get_home__123_v0() { - __AMBER_VAL_2=$(echo $HOME) - __AS=$? - if [ $__AS != 0 ]; then - echo "User installation requested, but unable to retrieve home directory from \$HOME environment." - exit 1 - fi - local home="${__AMBER_VAL_2}" - if [ $( - [ "_${home}" != "_" ] - echo $? - ) != 0 ]; then - echo "User installation requested, but unable to find home directory." - exit 1 - fi - __AF_get_home123_v0="${home}" - return 0 -} -get_bins_folder__124_v0() { - local user_only=$1 - if [ ${user_only} != 0 ]; then - get_home__123_v0 - __AF_get_home123_v0__55_18="${__AF_get_home123_v0}" - __AF_get_bins_folder124_v0="${__AF_get_home123_v0__55_18}/.local/bin" - return 0 - else - # Ensure /usr/local/bin exists for non-user installations - local bins_folder="/usr/local/bin" - test -d "${bins_folder}" >/dev/null 2>&1 - __AS=$? - if [ $__AS != 0 ]; then - sudo mkdir -p "${bins_folder}" >/dev/null 2>&1 - __AS=$? - if [ $__AS != 0 ]; then - echo "Failed to create ${bins_folder} directory." - exit 1 - fi - fi - __AF_get_bins_folder124_v0="${bins_folder}" - return 0 - fi -} -get_place__125_v0() { - local user_only=$1 - if [ ${user_only} != 0 ]; then - get_home__123_v0 - __AF_get_home123_v0__71_18="${__AF_get_home123_v0}" - get_arch__122_v0 - __AF_get_arch122_v0__71_42="${__AF_get_arch122_v0}" - __AF_get_place125_v0="${__AF_get_home123_v0__71_18}/.local/lib/${__AF_get_arch122_v0__71_42}/amber" - return 0 - else - __AF_get_place125_v0="/opt/amber" - return 0 - fi -} -__0_name="amber" -__1_target="amber" -__2_archive="amber.tar.xz" -has_failed__98_v0 "uname -a" -__AF_has_failed98_v0__10_13="$__AF_has_failed98_v0" -__AMBER_VAL_3=$(uname -a) -__AS=$? -__3_agent=$(if [ "$__AF_has_failed98_v0__10_13" != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_3}"; fi) -echo "" -get_latest_release_tag__130_v0() { - local tag_url="https://api.github.com/repos/amber-lang/${__0_name}/releases/latest" - __AMBER_VAL_4=$(curl -sL "${tag_url}") - __AS=$? - if [ $__AS != 0 ]; then - __AF_get_latest_release_tag130_v0='' - return $__AS - fi - local tag_json="${__AMBER_VAL_4}" - # Get the tag name from the JSON - __AMBER_VAL_5=$(echo "$tag_json" | grep -Eo "tag_name\"[^\"]*\"([^\"]+)\"" | grep -Eo "\"[^\"]+\"$" | grep -Eo "[^\"\s]+") - __AS=$? - if [ $__AS != 0 ]; then - __AF_get_latest_release_tag130_v0='' - return $__AS - fi - local tag="${__AMBER_VAL_5}" - __AF_get_latest_release_tag130_v0="${tag}" - return 0 -} -args=("$0" "$@") -get_os__121_v0 -__AF_get_os121_v0__28_14="${__AF_get_os121_v0}" -os="${__AF_get_os121_v0__28_14}" -get_arch__122_v0 -__AF_get_arch122_v0__29_16="${__AF_get_arch122_v0}" -arch="${__AF_get_arch122_v0__29_16}" -includes__116_v0 args[@] "--user" -__AF_includes116_v0__31_29="$__AF_includes116_v0" -user_only_install="$__AF_includes116_v0__31_29" -get_place__125_v0 ${user_only_install} -__AF_get_place125_v0__32_17="${__AF_get_place125_v0}" -place="${__AF_get_place125_v0__32_17}" -get_bins_folder__124_v0 ${user_only_install} -__AF_get_bins_folder124_v0__33_23="${__AF_get_bins_folder124_v0}" -bins_folder="${__AF_get_bins_folder124_v0__33_23}" -# Check if such directory exists -test -d "${place}" -__AS=$? -if [ $(echo $__AS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then - echo "Amber already installed" - echo "It seems that Amber is already installed on your system. (${place})" - echo "If you want to reinstall Amber, uninstall it first." - echo "(Find out more at https://docs.amber-lang.com/getting_started/installation#uninstallation)" - exit 2 -fi -# Check if curl is installed -has_failed__98_v0 "curl -V" -__AF_has_failed98_v0__47_8="$__AF_has_failed98_v0" -if [ "$__AF_has_failed98_v0__47_8" != 0 ]; then - echo "Curl is not installed on your system." - echo "Please install \`curl\` and try again." - exit 1 -fi -echo "Installing Amber... 🚀" -# Make the directories we need first to ensure we have permissions before downloading any files -# this decreases the chance that our script results in partial installation leaving assets behind -sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi) -# Create directory for amber -${sudo} mkdir -p "${place}" >/dev/null 2>&1 -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to create directory for amber." - if [ ${user_only_install} != 0 ]; then - echo "Please make sure that root user can access ${place} directory." - else - echo "Please make sure that your user can access ${place} directory." - fi - exit 1 -fi -if [ ${user_only_install} != 0 ]; then - mkdir -p "${bins_folder}" >/dev/null 2>&1 - __AS=$? - if [ $__AS != 0 ]; then - echo "Failed to create directory for amber bin at ${bins_folder}." - exit 1 - fi -fi -get_latest_release_tag__130_v0 -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to get the latest release tag." - echo "Please try again or use another download method." - exit 1 -fi -__AF_get_latest_release_tag130_v0__75_15="${__AF_get_latest_release_tag130_v0}" -tag="${__AF_get_latest_release_tag130_v0__75_15}" -# Set the download link -url="https://github.com/amber-lang/${__0_name}/releases/download/${tag}/amber-${arch}-${os}.tar.xz" -# Download amber -curl -L -o "${__2_archive}" "${url}" >/dev/null 2>&1 -__AS=$? -if [ $__AS != 0 ]; then - echo "Curl failed to download amber." - echo "Something went wrong. Please try again later." - exit 1 -fi -# Move archived version of amber -${sudo} mv "${__2_archive}" "${place}/${__2_archive}" -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to move amber to the installation directory." - echo "Please make sure that root user can access ${place} directory." - exit 1 -fi -# Unarchive amber -${sudo} tar --strip-components=1 -xvf ${place}/${__2_archive} -C ${place} >/dev/null 2>&1 -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to unarchive amber at ${place}/${__2_archive}" - echo "Please make sure that you have \`tar\` command installed." - exit 1 -fi -# Delete the archive -${sudo} rm ${place}/${__2_archive} -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to remove downloaded archive at ${place}/${__2_archive}" - exit 1 -fi -# Give permissions to execute amber -${sudo} chmod +x "${place}/${__1_target}" -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to give permissions to execute amber." - echo "Please make sure that root user can access ${place} directory." - exit 1 -fi -# Delete the previous symbolic link -file_exist__34_v0 "${bins_folder}/${__1_target}" -__AF_file_exist34_v0__119_8="$__AF_file_exist34_v0" -if [ "$__AF_file_exist34_v0__119_8" != 0 ]; then - ${sudo} rm "${bins_folder}/${__1_target}" - __AS=$? - if [ $__AS != 0 ]; then - echo "Failed to remove the previous amber symbol link." - echo "Please make sure that root user can access ${bins_folder} directory." - exit 1 - fi -fi -# Create amber symbol link -${sudo} ln -s "${place}/${__1_target}" "${bins_folder}/${__1_target}" -__AS=$? -if [ $__AS != 0 ]; then - echo "Failed to create amber symbol link." - echo "Please make sure that root user can access ${bins_folder} directory." - exit 1 -fi -input__95_v0 "Would you like to help improve Amber by sharing your OS info with our developer database? Enter your GitHub nickname (or any nickname) or type \`no\`:" -__AF_input95_v0__134_20="${__AF_input95_v0}" -nickname="${__AF_input95_v0__134_20}" -if [ $( - [ "_${nickname}" == "_no" ] - echo $? -) != 0 ]; then - # Send feedback to the server - curl -G --data-urlencode "agent=${__3_agent}" --data-urlencode "nickname=${nickname}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" >/dev/null 2>&1 - __AS=$? -fi -# Send success message -echo "Amber has been installed successfully. 🎉" -echo "> Now you can use amber by typing \`amber\` in your terminal." -if [ ${user_only_install} != 0 ]; then - echo "> Since you requested a user only install with \`--user\` ensure that ~/.local/bin is in your \\\$PATH." -fi diff --git a/setup/shared.ab b/setup/shared.ab deleted file mode 100644 index 44fb55d0..00000000 --- a/setup/shared.ab +++ /dev/null @@ -1,75 +0,0 @@ -import { has_failed } from "std/env" -import { array_contains } from "std/array" - -pub fun get_os(): Text { - // Determine OS type - let os_type = $ uname -s $ failed { - echo "Failed to determine OS type (using `uname` command)." - echo "Please try again or make sure you have it installed." - exit 1 - } - if os_type == "Darwin": - return "apple-darwin" - - if os_type != "Linux" { - echo "Unsupported OS type: {os_type}" - echo "Please try again or use another download method." - exit 1 - } - - if not has_failed("ls -l /lib | grep libc.musl"): - return "unknown-linux-musl" - - return "unknown-linux-gnu" -} - -pub fun get_arch(): Text { - // Determine architecture - let arch_type = $ uname -m $ failed { - echo "Failed to determine architecture." - echo "Please try again or use another download method." - exit 1 - } - - let arch = array_contains(["arm64", "aarch64"], arch_type) - then "aarch64" - else "x86_64" - - return arch -} - -fun get_home(): Text { - let home = $ echo \$HOME $ failed { - echo "User installation requested, but unable to retrieve home directory from $HOME environment." - exit 1 - } - if home == "" { - echo "User installation requested, but unable to find home directory." - exit 1 - } - return home -} - -pub fun get_bins_folder(user_only: Bool): Text { - if user_only { - return "{get_home()}/.local/bin" - } else { - // Ensure /usr/local/bin exists for non-user installations - let bins_folder = "/usr/local/bin" - silent $ test -d "{bins_folder}" $ failed { - silent $ sudo mkdir -p "{bins_folder}" $ failed { - echo "Failed to create {bins_folder} directory." - exit 1 - } - } - return bins_folder - } -} - -pub fun get_target_folder(user_only: Bool): Text { - if user_only { - return "{get_home()}/.local/lib/{get_arch()}/amber" - } else { - return "/opt/amber" - } -} diff --git a/setup/uninstall.ab b/setup/uninstall.ab deleted file mode 100644 index 94904d57..00000000 --- a/setup/uninstall.ab +++ /dev/null @@ -1,32 +0,0 @@ -import { array_contains } from "std/array" -import { get_arch, get_target_folder, get_bins_folder } from "./shared.ab" - -echo "" - -main(args) { - let arch = get_arch() - - let user_only_install = array_contains(args, "--user") - let target_folder = get_target_folder(user_only_install) - let bins_folder = get_bins_folder(user_only_install) - - trust $ test -d "{target_folder}" > /dev/null $ - - if status == 0 { - let sudo = user_only_install then "" else "sudo" - $ {sudo} rm -rf "{target_folder}" $ failed { - echo "Failed to remove Amber from {target_folder}" - echo "Make sure root has the correct permissions to access this directory" - exit 1 - } - $ {sudo} rm "{bins_folder}/amber" $ failed { - echo "Failed to remove Amber symlink from {bins_folder}" - echo "Make sure root has the correct permissions to access this directory" - exit 1 - } - echo "Uninstalled Amber successfully 🎉" - } - else { - echo "Amber is not installed" - } -} diff --git a/setup/uninstall.sh b/setup/uninstall.sh deleted file mode 100755 index 58c31180..00000000 --- a/setup/uninstall.sh +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/env bash -# Written in [Amber](https://amber-lang.com/) - -function exit__23_v0 { - local code=$1 - exit "${code}" -__AS=$? -} -function includes__24_v0 { - local arr=("${!1}") - local value=$2 - for v in "${arr[@]}" -do - if [ $([ "_${v}" != "_${value}" ]; echo $?) != 0 ]; then - __AF_includes24_v0=1; - return 0 -fi -done - __AF_includes24_v0=0; - return 0 -} -function get_arch__31_v0 { - __AMBER_VAL_0=$(uname -m); - __AS=$?; -if [ $__AS != 0 ]; then - echo "Failed to determine architecture." - echo "Please try again or use another download method." - exit__23_v0 1; - __AF_exit23_v0__30=$__AF_exit23_v0; - echo $__AF_exit23_v0__30 > /dev/null 2>&1 -fi; - local arch_type="${__AMBER_VAL_0}" - __AMBER_ARRAY_0=("arm64" "aarch64"); - includes__24_v0 __AMBER_ARRAY_0[@] "${arch_type}"; - __AF_includes24_v0__33=$__AF_includes24_v0; - local arch=$(if [ $__AF_includes24_v0__33 != 0 ]; then echo "aarch64"; else echo "x86_64"; fi) - __AF_get_arch31_v0="${arch}"; - return 0 -} -function get_home__32_v0 { - __AMBER_VAL_1=$(echo $HOME); - __AS=$?; -if [ $__AS != 0 ]; then - echo "User installation requested, but unable to retrieve home directory from $HOME environment." - exit__23_v0 1; - __AF_exit23_v0__43=$__AF_exit23_v0; - echo $__AF_exit23_v0__43 > /dev/null 2>&1 -fi; - local home="${__AMBER_VAL_1}" - if [ $([ "_${home}" != "_" ]; echo $?) != 0 ]; then - echo "User installation requested, but unable to find home directory." - exit__23_v0 1; - __AF_exit23_v0__47=$__AF_exit23_v0; - echo $__AF_exit23_v0__47 > /dev/null 2>&1 -fi - __AF_get_home32_v0="${home}"; - return 0 -} -function get_bins_folder__33_v0 { - local user_only=$1 - if [ ${user_only} != 0 ]; then - get_home__32_v0 ; - __AF_get_home32_v0__54="${__AF_get_home32_v0}"; - __AF_get_bins_folder33_v0="${__AF_get_home32_v0__54}/.local/bin"; - return 0 -else - local bins_folder="/usr/local/bin" - test -d "${bins_folder}" -__AS=$?; -if [ $__AS != 0 ]; then - sudo mkdir -p "${bins_folder}" > /dev/null 2>&1 -__AS=$?; -if [ $__AS != 0 ]; then - echo "Failed to create ${bins_folder} directory." - exit__23_v0 1 > /dev/null 2>&1; - __AF_exit23_v0__61=$__AF_exit23_v0; - echo $__AF_exit23_v0__61 > /dev/null 2>&1 -fi -fi - __AF_get_bins_folder33_v0="${bins_folder}"; - return 0 -fi -} -function get_place__34_v0 { - local user_only=$1 - if [ ${user_only} != 0 ]; then - get_home__32_v0 ; - __AF_get_home32_v0__70="${__AF_get_home32_v0}"; - get_arch__31_v0 ; - __AF_get_arch31_v0__70="${__AF_get_arch31_v0}"; - __AF_get_place34_v0="${__AF_get_home32_v0__70}/.local/lib/${__AF_get_arch31_v0__70}/amber"; - return 0 -else - __AF_get_place34_v0="/opt/amber"; - return 0 -fi -} -echo "" -args=("$@") - get_arch__31_v0 ; - __AF_get_arch31_v0__8="${__AF_get_arch31_v0}"; - arch="${__AF_get_arch31_v0__8}" - includes__24_v0 args[@] "--user"; - __AF_includes24_v0__10=$__AF_includes24_v0; - user_only_install=$__AF_includes24_v0__10 - get_place__34_v0 ${user_only_install}; - __AF_get_place34_v0__11="${__AF_get_place34_v0}"; - place="${__AF_get_place34_v0__11}" - get_bins_folder__33_v0 ${user_only_install}; - __AF_get_bins_folder33_v0__12="${__AF_get_bins_folder33_v0}"; - bins_folder="${__AF_get_bins_folder33_v0__12}" - test -d "${place}" > /dev/null -__AS=$? - if [ $(echo $__AS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then - sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi) - ${sudo} rm -rf "${place}" -__AS=$?; -if [ $__AS != 0 ]; then - echo "Failed to remove Amber from ${place}" - echo "Make sure root has the correct permissions to access this directory" - exit__23_v0 1; - __AF_exit23_v0__21=$__AF_exit23_v0; - echo $__AF_exit23_v0__21 > /dev/null 2>&1 -fi - ${sudo} rm "${bins_folder}/amber" -__AS=$?; -if [ $__AS != 0 ]; then - echo "Failed to remove Amber symlink from ${bins_folder}" - echo "Make sure root has the correct permissions to access this directory" - exit__23_v0 1; - __AF_exit23_v0__26=$__AF_exit23_v0; - echo $__AF_exit23_v0__26 > /dev/null 2>&1 -fi - echo "Uninstalled Amber successfully 🎉" -else - echo "Amber is not installed" -fi \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml deleted file mode 100644 index f1497ff5..00000000 --- a/snap/snapcraft.yaml +++ /dev/null @@ -1,52 +0,0 @@ -name: amber-bash -icon: assets/amber.png -title: Amber -base: core24 -adopt-info: amber-bash -summary: Amber the programming language compiled to bash -description: | - Programming language that compiles to Bash. It's a high level programming language that makes it easy to create shell scripts. - It's particularly well suited for cloud services. -contact: https://discord.com/invite/cjHjxbsDvZ -source-code: https://github.com/Ph0enixKM/Amber -issues: https://github.com/Ph0enixKM/Amber/issues -website: https://amber-lang.com/ -grade: stable -confinement: classic -compression: lzo - -parts: - amber-bash: - plugin: rust - source: . - build-packages: - - yq - build-attributes: - - enable-patchelf - override-pull: | - craftctl default - craftctl set version=$(cat $CRAFT_PART_SRC/Cargo.toml | tomlq -rc '.package.version') - prime: - - bin/amber - - resources/std - organize: - usr/bin: bin - std/*: std - - deps: - plugin: nil - stage-packages: - - bc - prime: - - bin/bc - build-attributes: - - enable-patchelf - organize: - usr/bin: bin - - -apps: - amber-bash: - command: bin/amber - environment: - STD_PATH: $SNAP/std diff --git a/src/stdlib.rs b/src/stdlib.rs index 422294df..50e89b99 100644 --- a/src/stdlib.rs +++ b/src/stdlib.rs @@ -2,16 +2,16 @@ use std::{env, fs, path::PathBuf}; #[cfg(not(debug_assertions))] fn get_install_dir() -> PathBuf { - let path = env::var("STD_PATH").expect("STD_PATH not set"); + let exec_path = env::current_exe().expect("Could not fetch executable file path."); - PathBuf::from(path) + PathBuf::from(exec_path.read_link().unwrap_or(exec_path)).join("std") } #[cfg(debug_assertions)] fn get_install_dir() -> PathBuf { let path = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - PathBuf::from(path).join("resources/std") + PathBuf::from(path).join("std") } pub fn resolve>(path: T) -> Option { diff --git a/resources/std/array.ab b/std/array.ab similarity index 100% rename from resources/std/array.ab rename to std/array.ab diff --git a/resources/std/date.ab b/std/date.ab similarity index 100% rename from resources/std/date.ab rename to std/date.ab diff --git a/resources/std/env.ab b/std/env.ab similarity index 100% rename from resources/std/env.ab rename to std/env.ab diff --git a/resources/std/fs.ab b/std/fs.ab similarity index 100% rename from resources/std/fs.ab rename to std/fs.ab diff --git a/resources/std/http.ab b/std/http.ab similarity index 100% rename from resources/std/http.ab rename to std/http.ab diff --git a/resources/std/math.ab b/std/math.ab similarity index 100% rename from resources/std/math.ab rename to std/math.ab diff --git a/resources/std/text.ab b/std/text.ab similarity index 100% rename from resources/std/text.ab rename to std/text.ab