Skip to content

Commit

Permalink
Merge pull request #39 from shakacode/linux-arm64
Browse files Browse the repository at this point in the history
Add Linux arm64 binary
  • Loading branch information
alex35mil authored Sep 19, 2023
2 parents 13c2a37 + 97b6027 commit 8cfbf98
Show file tree
Hide file tree
Showing 15 changed files with 350 additions and 55 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
.direnv/
.devbox/
.vscode/
.envrc
.cache
Expand All @@ -12,4 +13,6 @@ node_modules/
/_release
/lib/lib/
/examples/lib/
/scripts/aws.env
/scripts/aws.pem
rescript-logger-ppx.install
3 changes: 3 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
22 changes: 22 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
23 changes: 23 additions & 0 deletions devbox.lock
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
2 changes: 1 addition & 1 deletion esy.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-logger-ppx",
"version": "3.0.0",
"version": "3.1.0",
"description": "Logging implementation for ReScript",
"author": "Alex Fedoseev <alex@fedoseev.mx>",
"license": "MIT",
Expand Down
61 changes: 61 additions & 0 deletions nix/ocaml/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions nix/ocaml/flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rescript-logger",
"version": "3.0.0",
"version": "3.1.0",
"description": "Logging implementation for ReScript",
"author": "Alex Fedoseev <alex@fedoseev.mx>",
"license": "MIT",
Expand Down
52 changes: 0 additions & 52 deletions release.sh

This file was deleted.

69 changes: 69 additions & 0 deletions scripts/build-linux-arm64.sh
Original file line number Diff line number Diff line change
@@ -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."
16 changes: 16 additions & 0 deletions scripts/build-macos-arm64.sh
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 8cfbf98

Please sign in to comment.