From 38367e5b03d30eba9243f23b32c02719fc648210 Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Tue, 19 Sep 2023 15:13:53 +0400 Subject: [PATCH 1/5] Fix shell.nix formatting --- shell.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From fcd9641d3d431b7a6c109ef2604762df079c2568 Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Tue, 19 Sep 2023 15:14:06 +0400 Subject: [PATCH 2/5] Add devbox support --- .gitignore | 1 + README.md | 27 ++++++++++++++++++++ devbox.json | 21 +++++++++++++++ devbox.lock | 19 ++++++++++++++ nix/ocaml/flake.lock | 61 ++++++++++++++++++++++++++++++++++++++++++++ nix/ocaml/flake.nix | 47 ++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+) create mode 100644 devbox.json create mode 100644 devbox.lock create mode 100644 nix/ocaml/flake.lock create mode 100644 nix/ocaml/flake.nix diff --git a/.gitignore b/.gitignore index a7c02de..f2b9b0b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ node_modules/ .direnv/ +.devbox/ .vscode/ .envrc .cache 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..0fd719b --- /dev/null +++ b/devbox.json @@ -0,0 +1,21 @@ +{ + "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" + ], + "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..1999ed3 --- /dev/null +++ b/devbox.lock @@ -0,0 +1,19 @@ +{ + "lockfile_version": "1", + "packages": { + "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/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; + }; + } + ); +} From fef743e21639d2456b80f332d70f96508a08c3e6 Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Tue, 19 Sep 2023 17:21:49 +0400 Subject: [PATCH 3/5] Update release scripts --- .gitignore | 2 + devbox.json | 3 +- devbox.lock | 4 ++ release.sh | 52 ------------------------ scripts/build-linux-arm64.sh | 69 ++++++++++++++++++++++++++++++++ scripts/build-macos-arm64.sh | 16 ++++++++ scripts/release.sh | 49 +++++++++++++++++++++++ scripts/user-data.linux-arm64.sh | 27 +++++++++++++ 8 files changed, 169 insertions(+), 53 deletions(-) delete mode 100755 release.sh create mode 100755 scripts/build-linux-arm64.sh create mode 100755 scripts/build-macos-arm64.sh create mode 100755 scripts/release.sh create mode 100644 scripts/user-data.linux-arm64.sh diff --git a/.gitignore b/.gitignore index f2b9b0b..9ab40cd 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ node_modules/ /_release /lib/lib/ /examples/lib/ +/scripts/aws.env +/scripts/aws.pem rescript-logger-ppx.install diff --git a/devbox.json b/devbox.json index 0fd719b..56383f1 100644 --- a/devbox.json +++ b/devbox.json @@ -7,7 +7,8 @@ "path:./nix/ocaml#merlin", "path:./nix/ocaml#lsp", "nodejs", - "yarn" + "yarn", + "awscli2" ], "shell": { "init_hook": [ diff --git a/devbox.lock b/devbox.lock index 1999ed3..ac39a3b 100644 --- a/devbox.lock +++ b/devbox.lock @@ -1,6 +1,10 @@ { "lockfile_version": "1", "packages": { + "awscli2": { + "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#awscli2", + "source": "nixpkg" + }, "nodejs": { "resolved": "github:NixOS/nixpkgs/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62#nodejs", "source": "nixpkg" 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; +' From 3a902d82f582f80f7af2a64ec3c394df6d4d0b7d Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Tue, 19 Sep 2023 17:23:18 +0400 Subject: [PATCH 4/5] Update HISTORY --- HISTORY.md | 3 +++ 1 file changed, 3 insertions(+) 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`. From 97b6027feb3285b112902b16db96f176da1176dd Mon Sep 17 00:00:00 2001 From: Alex Fedoseev Date: Tue, 19 Sep 2023 17:25:54 +0400 Subject: [PATCH 5/5] v3.1.0 --- esy.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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",