Skip to content
This repository has been archived by the owner on Oct 8, 2023. It is now read-only.

Commit

Permalink
Use bindgen bash scripts in GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lithiumtoast committed May 3, 2023
1 parent 8ce0c22 commit fcce562
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
fail-fast: false
matrix:
platform:
- { name: Windows, os: windows-latest, rid: win, config_filename: config-extract-windows.json }
- { name: macOS, os: macos-latest, rid: osx, config_filename: config-extract-macos.json }
- { name: Linux, os: ubuntu-latest, rid: linux, config_filename: config-extract-linux.json }
- { name: Windows, os: windows-latest, rid: win }
- { name: macOS, os: macos-latest, rid: osx }
- { name: Linux, os: ubuntu-latest, rid: linux }

steps:
- name: "Clone Git repository"
Expand All @@ -33,7 +33,7 @@ jobs:

- name: "Read C code: extract ${{ matrix.platform.rid }}"
shell: bash
run: cd ./bindgen && castffi extract --config "./${{ matrix.platform.config_filename }}"
run: cd ./bindgen && ./extract.sh

- name: "Upload C code platform abstract syntax trees"
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -76,7 +76,7 @@ jobs:

- name: "Generate cross-platform AST"
shell: bash
run: cd ./bindgen && castffi merge --inputDirectoryPath "./ast" --outputFilePath "./ast-cross-platform.json"
run: cd ./bindgen && ./merge.sh

- name: "Upload cross-platform AST"
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:

- name: "Generate C# code"
shell: bash
run: cd ./bindgen && c2cs generate --config "./config-generate-cs.json"
run: cd ./bindgen && ./generate.sh

- name: "Upload generated C# code"
uses: actions/upload-artifact@v2
Expand Down
38 changes: 38 additions & 0 deletions bindgen/extract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

function get_host_operating_system() {
local UNAME_STRING="$(uname -a)"
case "${UNAME_STRING}" in
*Microsoft*) local HOST_OS="windows";;
*microsoft*) local HOST_OS="windows";;
Linux*) local HOST_OS="linux";;
Darwin*) local HOST_OS="macos";;
CYGWIN*) local HOST_OS="linux";;
MINGW*) local HOST_OS="windows";;
*Msys) local HOST_OS="windows";;
*) local HOST_OS="UNKNOWN:${UNAME_STRING}"
esac
echo "$HOST_OS"
return 0
}

OS="$(get_host_operating_system)"

if [[ "$OS" == "windows" ]]; then
CASTFFI_CONFIG_FILE_PATH="$DIRECTORY/config-extract-windows.json"
elif [[ "$OS" == "macos" ]]; then
CASTFFI_CONFIG_FILE_PATH="$DIRECTORY/config-extract-macos.json"
elif [[ "$OS" == "linux" ]]; then
CASTFFI_CONFIG_FILE_PATH="$DIRECTORY/config-extract-linux.json"
else
echo "Error: Unknown operating system '$OS'" >&2
exit 1
fi

if ! [[ -x "$(command -v castffi)" ]]; then
echo "Error: 'castffi' is not installed. Please visit https://github.com/bottlenoselabs/CAstFfi for instructions to install the CAstFfi tool." >&2
exit 1
fi

castffi extract --config "$CASTFFI_CONFIG_FILE_PATH"
9 changes: 9 additions & 0 deletions bindgen/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

if ! [[ -x "$(command -v c2cs)" ]]; then
echo "Error: 'c2cs' is not installed. Please visit https://github.com/bottlenoselabs/C2CS for instructions to install the C2CS tool." >&2
exit 1
fi

c2cs generate -config "$DIRECTORY/config-generate-cs.json"
9 changes: 9 additions & 0 deletions bindgen/merge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

if ! [[ -x "$(command -v castffi)" ]]; then
echo "Error: 'castffi' is not installed. Please visit https://github.com/bottlenoselabs/CAstFfi for instructions to install the CAstFfi tool." >&2
exit 1
fi

castffi merge --inputDirectoryPath "$DIRECTORY/ast" --outputFilePath "$DIRECTORY/x-ast/ast-cross-platform.json"

0 comments on commit fcce562

Please sign in to comment.