diff --git a/.gitignore b/.gitignore index a7c02de..9ab40cd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ .direnv/ +.devbox/ .vscode/ .envrc .cache @@ -12,4 +13,6 @@ node_modules/ /_release /lib/lib/ /examples/lib/ +/scripts/aws.env +/scripts/aws.pem rescript-logger-ppx.install diff --git a/HISTORY.md b/HISTORY.md index 668af45..c976839 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,9 @@ # History ## UNRELEASED +## 3.1.0 +- Add Linux `arm64` binary. + ## 3.0.0 - **[BREAKING]** Remove `filePath` from `Location.t`. - Upgrade to `rescript@10`. diff --git a/README.md b/README.md index 3a867d7..2d1dcc7 100644 --- a/README.md +++ b/README.md @@ -421,6 +421,33 @@ cd lib && yarn run build cd ../examples && yarn run build ``` +### Devbox flow +Clone repo and either enter the Devbox shell: + +``` +devbox shell +``` + +Or use [`direnv`](https://direnv.net/) and create `.envrc` file in the root directory of the project by running: + +``` +devbox generate direnv --print-envrc +``` + +Then install deps: + +```shell +yarn install +``` + +Build loggers and ppx: + +```shell +devbox run build +cd lib && yarn run build +cd ../examples && yarn run build +``` + ### Esy flow Clone repo and install deps: diff --git a/devbox.json b/devbox.json new file mode 100644 index 0000000..56383f1 --- /dev/null +++ b/devbox.json @@ -0,0 +1,22 @@ +{ + "packages": [ + "path:./nix/ocaml#ocaml", + "path:./nix/ocaml#dune", + "path:./nix/ocaml#findlib", + "path:./nix/ocaml#ppxlib", + "path:./nix/ocaml#merlin", + "path:./nix/ocaml#lsp", + "nodejs", + "yarn", + "awscli2" + ], + "shell": { + "init_hook": [ + "export PATH=$PATH:node_modules/.bin" + ], + "scripts": { + "build": "dune build", + "test": "dune exec test.exe" + } + } +} diff --git a/devbox.lock b/devbox.lock new file mode 100644 index 0000000..ac39a3b --- /dev/null +++ b/devbox.lock @@ -0,0 +1,23 @@ +{ + "lockfile_version": "1", + "packages": { + "awscli2": { + "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#awscli2", + "source": "nixpkg" + }, + "nodejs": { + "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#nodejs", + "source": "nixpkg" + }, + "path:./nix/ocaml#dune": {}, + "path:./nix/ocaml#findlib": {}, + "path:./nix/ocaml#lsp": {}, + "path:./nix/ocaml#merlin": {}, + "path:./nix/ocaml#ocaml": {}, + "path:./nix/ocaml#ppxlib": {}, + "yarn": { + "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#yarn", + "source": "nixpkg" + } + } +} diff --git a/esy.json b/esy.json index 6226267..ab88cd3 100644 --- a/esy.json +++ b/esy.json @@ -1,6 +1,6 @@ { "name": "rescript-logger-ppx", - "version": "3.0.0", + "version": "3.1.0", "description": "Logging implementation for ReScript", "author": "Alex Fedoseev ", "license": "MIT", diff --git a/nix/ocaml/flake.lock b/nix/ocaml/flake.lock new file mode 100644 index 0000000..15e4c30 --- /dev/null +++ b/nix/ocaml/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1694959747, + "narHash": "sha256-CXQ2MuledDVlVM5dLC4pB41cFlBWxRw4tCBsFrq3cRk=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "970a59bd19eff3752ce552935687100c46e820a5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/nix/ocaml/flake.nix b/nix/ocaml/flake.nix new file mode 100644 index 0000000..dc609e9 --- /dev/null +++ b/nix/ocaml/flake.nix @@ -0,0 +1,47 @@ +{ + description = "OCaml 4.12 packages for ReScript PPX development"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + overlay = (final: prev: { + ocaml-ng = prev.ocaml-ng // { + ocamlPackages_4_12 = prev.ocaml-ng.ocamlPackages_4_12 // { + ppxlib = prev.ocaml-ng.ocamlPackages_4_12.ppxlib.overrideAttrs (_: { + version = "git"; + src = pkgs.fetchFromGitHub { + owner = "zth"; + repo = "ppxlib"; + rev = "32f83395fb89693a873541298b6367449f23bc4a"; + sha256 = "sha256-8bkmeFh5Unda8n3F2MQWi81QPt2NdkwFcy4wZTJ0STo="; + }; + patches = []; + }); + }; + }; + }); + + pkgs = import nixpkgs { + inherit system; + overlays = [ overlay ]; + }; + + ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_12; + in + { + packages = { + ocaml = ocamlPackages.ocaml; + dune = ocamlPackages.dune_3; + findlib = ocamlPackages.findlib; + ppxlib = ocamlPackages.ppxlib; + merlin = ocamlPackages.merlin; + lsp = ocamlPackages.ocaml-lsp; + }; + } + ); +} diff --git a/package.json b/package.json index 37b4489..f63293f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rescript-logger", - "version": "3.0.0", + "version": "3.1.0", "description": "Logging implementation for ReScript", "author": "Alex Fedoseev ", "license": "MIT", diff --git a/release.sh b/release.sh deleted file mode 100755 index e3e380b..0000000 --- a/release.sh +++ /dev/null @@ -1,52 +0,0 @@ -set -e -set -o pipefail - -ARCH=$(uname -m) -PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]') - -OPAM_FILE=$(basename -- $(find *.opam)) -LIB="${OPAM_FILE%.*}" - -SOURCE_BIN="_build/default/ppx/bin/bin.exe" -RELEASE_DIR="_release" -RELEASE_ZIP="$RELEASE_DIR/release.zip" -RELEASE_BIN_DIR="$RELEASE_DIR/bin" -RELEASE_BIN="$RELEASE_BIN_DIR/$LIB-$PLATFORM-$ARCH.exe" - -if [ ! -f "$RELEASE_ZIP" ]; then - echo "$RELEASE_ZIP does not exist. Download it from Github and put in $RELEASE_DIR/ dir." - exit 1 -fi - -echo "=== Releasing $LIB" -echo "=== Unzipping release archive" -unzip -d $RELEASE_DIR $RELEASE_ZIP -rm $RELEASE_ZIP -tree -a -L 2 $RELEASE_DIR - -echo "" -echo "=== Preparing $PLATFORM $ARCH binary" - -CHMOD=$(stat -c %a "$RELEASE_BIN_DIR/$(ls $RELEASE_BIN_DIR | head -n 1)") - -dune build -cp $SOURCE_BIN $RELEASE_BIN -chmod $CHMOD $RELEASE_BIN -tree -a -L 2 $RELEASE_DIR - -echo "" -echo "=== Publishing to npm" -cd $RELEASE_DIR -rm .DS_Store >/dev/null 2>&1 || true - -echo "package.json:" -cat package.json -echo "" - -npm publish -cd .. - -echo "" -echo "=== Cleaning up" -rm -rf $RELEASE_DIR/* -tree -a -L 2 $RELEASE_DIR diff --git a/scripts/build-linux-arm64.sh b/scripts/build-linux-arm64.sh new file mode 100755 index 0000000..4eb3a74 --- /dev/null +++ b/scripts/build-linux-arm64.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +set -euo pipefail + +export $(cat scripts/aws.env | xargs) + +ARCH="arm64" +PLATFORM="linux" + +BIN="$LIB-$PLATFORM-$ARCH.exe" +REMOTE_BIN="~/rescript-logger/$RELEASE_DIR/$BIN" +RELEASE_BIN="$RELEASE_BIN_DIR/$BIN" + +echo "" +echo "=== Preparing $PLATFORM $ARCH binary" + +echo "Creating EC2 instance" +INSTANCE_ID=$( + aws ec2 run-instances \ + --image-id ami-0f69dd1d0d03ad669 \ + --count 1 \ + --instance-type m6g.medium \ + --key-name rescript-logger \ + --user-data file://scripts/user-data.linux-arm64.sh \ + --tag-specifications="ResourceType=instance,Tags=[{Key=rescript-logger,Value=''}]" \ + | jq -r ".Instances[0].InstanceId" +) +echo "EC2 instance $INSTANCE_ID created" + +echo "Getting public IP" +while : +do + INSTANCE_IP=$( + aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r ".Reservations[0].Instances[0].PublicIpAddress" + ) + if [ -n "$INSTANCE_IP" ]; + then + echo "Instance is available at $INSTANCE_IP" + break; + else + sleep 5; + fi +done + +echo "Waiting for the build to complete" + +sleep 300 + +USER="ubuntu" + +while : +do + if ssh -o StrictHostKeyChecking=no -q -i scripts/aws.pem $USER@$INSTANCE_IP test -f "$REMOTE_BIN"; + then + echo "Binary is ready. Downloading." + break + else + sleep 5 + fi +done + +scp -i scripts/aws.pem $USER@$INSTANCE_IP:$REMOTE_BIN $RELEASE_BIN +echo "Downloaded." + +chmod $CHMOD $RELEASE_BIN + +echo "Terminating instance." +aws ec2 terminate-instances --instance-ids $INSTANCE_ID +echo "Instance terminated." diff --git a/scripts/build-macos-arm64.sh b/scripts/build-macos-arm64.sh new file mode 100755 index 0000000..25110b4 --- /dev/null +++ b/scripts/build-macos-arm64.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -euo pipefail + +ARCH=$(uname -m) +PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]') + +echo "" +echo "=== Preparing $PLATFORM $ARCH binary" + +SOURCE_BIN="_build/default/ppx/bin/bin.exe" +RELEASE_BIN="$RELEASE_BIN_DIR/$LIB-$PLATFORM-$ARCH.exe" + +dune build +cp $SOURCE_BIN $RELEASE_BIN +chmod $CHMOD $RELEASE_BIN diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..adfc869 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -euo pipefail + +OPAM_FILE=$(basename -- "$(find *.opam)") + +export LIB="${OPAM_FILE%.*}" +export RELEASE_DIR="_release" +export RELEASE_ZIP="$RELEASE_DIR/release.zip" +export RELEASE_BIN_DIR="$RELEASE_DIR/bin" + +echo "=== Releasing $LIB" + +if [ ! -f "$RELEASE_ZIP" ]; then + echo "$RELEASE_ZIP does not exist. Download it from Github and put in $RELEASE_DIR/ dir." + exit 1 +fi + +echo "=== Unzipping release archive" +unzip -d $RELEASE_DIR $RELEASE_ZIP +rm $RELEASE_ZIP + +echo "Release tree:" +tree -a -L 2 $RELEASE_DIR + +export CHMOD=$(stat -c %a "$RELEASE_BIN_DIR/$(ls $RELEASE_BIN_DIR | head -n 1)") + +./scripts/build-macos-arm64.sh +./scripts/build-linux-arm64.sh + +echo "Release tree:" +tree -a -L 2 $RELEASE_DIR + +echo "" +echo "=== Publishing to npm" +cd $RELEASE_DIR +rm .DS_Store >/dev/null 2>&1 || true + +echo "package.json:" +cat package.json +echo "" + +npm publish +cd .. + +echo "" +echo "=== Cleaning up" +rm -rf $RELEASE_DIR/* +tree -a -L 2 $RELEASE_DIR diff --git a/scripts/user-data.linux-arm64.sh b/scripts/user-data.linux-arm64.sh new file mode 100644 index 0000000..0efb0ff --- /dev/null +++ b/scripts/user-data.linux-arm64.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +set -euo pipefail + +exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 + +export DEBIAN_FRONTEND=noninteractive + +apt update + +sudo -u ubuntu bash -xec 'pwd; +cd ~; +curl -fsSL https://get.jetpack.io/devbox -o devbox.sh; +bash devbox.sh -f; +git clone https://github.com/shakacode/rescript-logger.git; +cd rescript-logger; +devbox shell; +devbox run build; +ARCH=arm64; +PLATFORM=linux; +OPAM_FILE=$(basename -- $(find *.opam)); +LIB="${OPAM_FILE%.*}"; +SOURCE_BIN="_build/default/ppx/bin/bin.exe"; +RELEASE_BIN="_release/$LIB-$PLATFORM-$ARCH.exe"; +mkdir -p $(dirname $RELEASE_BIN); +cp $SOURCE_BIN $RELEASE_BIN; +' diff --git a/shell.nix b/shell.nix index eb26e63..aa5f43a 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ with import {}; with pkgs.ocaml-ng.ocamlPackages_4_12; -let +let ppxlib-rescript = ppxlib.overrideAttrs (_: { version = "git"; src = fetchFromGitHub {