Skip to content

Commit

Permalink
Merge pull request #116 from shakacode/linux-arm64
Browse files Browse the repository at this point in the history
Add linux arm64 binary
  • Loading branch information
alex35mil authored Mar 27, 2023
2 parents 683ac84 + 262a357 commit fa57cb4
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ yarn-error.log
/examples/lib/
/lib/lib/
/specs/lib/
/scripts/aws.env
/scripts/aws.pem
/ppx/test/**/*.cm[itj]
re-formality-ppx.install
5 changes: 4 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# History

## 4.0.0-beta.18
* Add native Linux `arm64` support [#116](https://github.com/shakacode/re-formality/pull/116).

## 4.0.0-beta.17
* Add native `arm64` support [#111](https://github.com/shakacode/re-formality/pull/111).
* Add native macOS `arm64` support [#111](https://github.com/shakacode/re-formality/pull/111).

## 4.0.0-beta.16
* Add support for m1 through rosetta [#106](https://github.com/shakacode/re-formality/pull/106).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "re-formality",
"version": "4.0.0-beta.17",
"version": "4.0.0-beta.18",
"description": "Form validation tool for @rescript/react",
"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="aarch64"
PLATFORM="linux"

BIN="$LIB-$PLATFORM-$ARCH.exe"
REMOTE_BIN="~/re-formality/$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 re-formality \
--user-data file://scripts/user-data.linux-arm64.sh \
--tag-specifications="ResourceType=instance,Tags=[{Key=re-formality,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
49 changes: 49 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions scripts/user-data.linux-arm64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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
apt install opam -y

sudo -u ubuntu bash -xec 'pwd;
OCAML_VERSION=4.12.0;
opam init --no;
opam switch create $OCAML_VERSION;
eval $(opam env --switch=$OCAML_VERSION);
opam install -y dune ppxlib reason alcotest;
cd ~;
git clone https://github.com/shakacode/re-formality.git;
cd re-formality;
dune build;
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_BIN="_release/$LIB-$PLATFORM-$ARCH.exe";
mkdir -p $(dirname $RELEASE_BIN);
cp $SOURCE_BIN $RELEASE_BIN;
'
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mkShell {
ocaml-lsp
nodejs
yarn
awscli2
darwin.apple_sdk.frameworks.CoreServices
];
}

0 comments on commit fa57cb4

Please sign in to comment.