Skip to content

Commit

Permalink
Problem: cross-compiling don't work (#874)
Browse files Browse the repository at this point in the history
* Problem: cross-compiling don't work

Solution:
- remove some obstacles, now it at least works for linux.
- darwin still need some fixes in nixpkgs side, see: NixOS/nixpkgs#216431

update release flow

upload build result to check

Problem: windows build in CI fails (#868)

* Problem: windows build in CI fails

Solution:
- patch grocksdb to remove binding of not exported apis
- add workflow to test windows build in PR

* use crypto-org-chain fork

update gomod2nix

fix mac cross compiling

fix cross-compiling tarball

windows bundle script

support windows tarball

add unified job for cross-compiling

grocksdb link options

configure differnt build machine for different hosts

don't fail fast

simplify

don't run unittest in nix build

update grocksdb dependency

tidy

fix grocksdb

grocksdb upstream repo

* Update app/versiondb_placeholder.go

Signed-off-by: yihuang <huang@crypto.com>

* update nixpkgs

* temp

* cleanup and remove goreleaser

* use buildPackages.go

* fix workflow

* fix workflow

* Update scripts/release.sh

Signed-off-by: yihuang <huang@crypto.com>

* fix default name of GITHUB_REF_NAME

* fix ref name

* escape ref name to be used as file name

* fix escape

* fix arm64

* fix darwin cross-compiling

* fix darwin cross-compiling

---------

Signed-off-by: yihuang <huang@crypto.com>
  • Loading branch information
yihuang authored Feb 23, 2023
1 parent bbb8150 commit 65d7297
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 2,357 deletions.
35 changes: 21 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,40 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-go@v3
with:
go-version: 1.20.0
- id: changed-files
uses: tj-actions/changed-files@v34
with:
files: |
*.go
*.mod
*.sum
- run: |
# without rocksdb
make build
# with rocksdb and enable versiondb
nix profile install nixpkgs#rocksdb
export PKG_CONFIG_PATH=$HOME/.nix-profile/lib/pkgconfig
export CGO_CFLAGS="$(pkg-config --cflags rocksdb)" CGO_LDFLAGS="$(pkg-config --libs rocksdb)"
COSMOS_BUILD_OPTIONS=rocksdb make build
- uses: cachix/cachix-action@v12
if: steps.changed-files.outputs.any_changed == 'true'
with:
name: cronos
# github don't pass secrets for pull request from fork repos,
# in that case the push is disabled naturally.
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: Run build
run: ./scripts/release.sh
if: steps.changed-files.outputs.any_changed == 'true'
- uses: actions/upload-artifact@v3
with:
name: "cronosd-tarball-${{ matrix.os }}"
path: "*.tar.gz"
if-no-files-found: ignore

unittest:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -116,7 +123,7 @@ jobs:
set +e
(git diff --no-ext-diff --exit-code)
echo "name=changed::$?" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: steps.changes.outputs.changed == 1
with:
name: gomod2nix.toml
Expand Down Expand Up @@ -159,7 +166,7 @@ jobs:
set +e
(git diff --no-ext-diff --exit-code)
echo "name=changed::$?" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: steps.changes.outputs.changed == 1
with:
name: contracts_out
Expand Down
176 changes: 37 additions & 139 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,193 +9,91 @@ permissions:
contents: write

jobs:
goreleaser:
release:
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: setup release environment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
- name: build and upload goreleaser binaries
run: make release

x86_64:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
needs: ["goreleaser"]
runs-on: ${{ matrix.os }}
environment: release
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- uses: apple-actions/import-codesign-certs@v1
if: matrix.os == 'macos-latest'
with:
p12-file-base64: ${{ secrets.MAC_CODE_SIGN_CERT }}
p12-password: ${{ secrets.MAC_CODE_SIGN_CERT_PASS }}
- uses: cachix/cachix-action@v12
with:
name: cronos
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: build linux/mac x86_64 binaries
env:
MAC_CODE_API_KEY: ${{ secrets.MAC_CODE_API_KEY }}
MAC_CODE_API_KEY_ID: ${{ secrets.MAC_CODE_API_KEY_ID }}
MAC_CODE_API_ISSUER_ID: ${{ secrets.MAC_CODE_API_ISSUER_ID }}
MAC_CODE_API_DEVELOPER_ID: ${{ secrets.MAC_CODE_API_DEVELOPER_ID }}
run: |
PLATFORM="$(uname -s)_x86_64"
BUILD_TYPE="tarball"
FLAKE="github:${GITHUB_REPOSITORY}/${GITHUB_REF_NAME}"
build() {
NETWORK=$1
nix build -L "${FLAKE}#cronosd${NETWORK}-${BUILD_TYPE}"
OUTPUT="cronos_${GITHUB_REF_NAME:1}${NETWORK}_${PLATFORM}"
if [ "$(uname -s)" == "Darwin" ]; then
./scripts/codesign_macos.sh ./result
mv signed.tar.gz "$OUTPUT.tar.gz"
else
cp result "$OUTPUT.tar.gz"
fi
}
build ""
build "-testnet"

- name: build binaries
run: |
# install sha256sum
nix-env -i coreutils -f '<nixpkgs>'
sha256sum *.tar.gz > "checksums-$PLATFORM.txt"
# build binaries
./scripts/release.sh
# update checksum and upload
sha256sum *.tar.gz > "checksums.txt"
echo 'FILES<<EOF' >> $GITHUB_ENV
ls -1 *.tar.gz >> $GITHUB_ENV
ls -1 checksums-*.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
cat $GITHUB_ENV
- name: upload linux/mac x86_64 binaries
- name: upload binaries
uses: softprops/action-gh-release@v1
with:
draft: true
files: "${{ env.FILES }}"

aarch64-linux:
needs: ["goreleaser"]
runs-on: ubuntu-latest
release-macos:
# runs sequentially to avoid creating duplicated release
needs: ["release"]
runs-on: macos-latest
environment: release
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-22.11
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- run: |
DEBIAN_FRONTEND=noninteractive
sudo apt-get update -q -y && sudo apt-get install -q -y qemu-system-aarch64 qemu-efi binfmt-support qemu-user-static
mkdir -p ~/.config/nix
sudo bash -c "echo system-features = aarch64-linux arm-linux >> /etc/nix/nix.conf"
- uses: apple-actions/import-codesign-certs@v1
with:
p12-file-base64: ${{ secrets.MAC_CODE_SIGN_CERT }}
p12-password: ${{ secrets.MAC_CODE_SIGN_CERT_PASS }}
- uses: cachix/cachix-action@v12
with:
name: cronos
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- name: build linux arm64 binaries
- name: build binaries
env:
PLATFORM: Linux_arm64
MAC_CODE_API_KEY: ${{ secrets.MAC_CODE_API_KEY }}
MAC_CODE_API_KEY_ID: ${{ secrets.MAC_CODE_API_KEY_ID }}
MAC_CODE_API_ISSUER_ID: ${{ secrets.MAC_CODE_API_ISSUER_ID }}
MAC_CODE_API_DEVELOPER_ID: ${{ secrets.MAC_CODE_API_DEVELOPER_ID }}
run: |
BUILD_TYPE="tarball"
FLAKE="github:${GITHUB_REPOSITORY}/${GITHUB_REF_NAME}"
nix build -L --extra-platforms aarch64-linux ${FLAKE}#packages.aarch64-linux.cronosd-$BUILD_TYPE
cp result cronos_${GITHUB_REF_NAME:1}_${PLATFORM}.tar.gz
# install sha256sum
nix-env -i coreutils -f '<nixpkgs>'
nix build -L --extra-platforms aarch64-linux ${FLAKE}#packages.aarch64-linux.cronosd-testnet-$BUILD_TYPE
cp result cronos_${GITHUB_REF_NAME:1}-testnet_${PLATFORM}.tar.gz
# build binaries
./scripts/release.sh
sha256sum *.tar.gz > checksums-$PLATFORM.txt
# codesign
for tarball in *.tar.gz;
do
./scripts/codesign_macos.sh $tarball
mv signed.tar.gz $tarball
done
# update checksum and upload
sha256sum *.tar.gz > "checksums-macos.txt"
echo 'FILES<<EOF' >> $GITHUB_ENV
ls -1 *.tar.gz >> $GITHUB_ENV
ls -1 checksums-*.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
cat $GITHUB_ENV
- name: upload linux arm64 binaries
- name: upload binaries
uses: softprops/action-gh-release@v1
with:
draft: true
files: "${{ env.FILES }}"

x86_64-windows:
needs: ["goreleaser"]
runs-on: windows-latest
environment: release
steps:
- name: get source
uses: actions/checkout@v3
with:
submodules: true
- name: setup msys2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: false
install: git msys2-devel base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-rocksdb mingw-w64-x86_64-go mingw-w64-x86_64-jq mingw-w64-x86_64-dlfcn
- name: get rocksdb & build
env:
PLATFORM: Windows_x86_64
shell: msys2 {0}
run: |
uname -a
export GOROOT=/mingw64/lib/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
export CGO_CFLAGS="-I/mingw64/include/rocksdb"
export CGO_LDFLAGS="-L/mingw64/lib -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"
echo $PATH
go version
wget https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-rocksdb-6.26.1-1-any.pkg.tar.zst
pacman -U mingw-w64-x86_64-rocksdb-6.26.1-1-any.pkg.tar.zst --noconfirm
COSMOS_BUILD_OPTIONS=rocksdb make build
ls -la ./build/
mv ./build/cronosd ./build/cronosd.exe
cp /mingw64/bin/libbz2-1.dll ./build
cp /mingw64/bin/libgcc_s_seh-1.dll ./build
cp /mingw64/bin/liblz4.dll ./build
cp /mingw64/bin/librocksdb.dll ./build
cp /mingw64/bin/libsnappy.dll ./build
cp /mingw64/bin/libstdc++-6.dll ./build
cp /mingw64/bin/libwinpthread-1.dll ./build
cp /mingw64/bin/libzstd.dll ./build
cp /mingw64/bin/zlib1.dll ./build
cd ./build
tar cvfz ../cronos.tar.gz *
cd ..
mv ./cronos.tar.gz cronos_${GITHUB_REF_NAME:1}_${PLATFORM}.tar.gz
NETWORK=testnet COSMOS_BUILD_OPTIONS=rocksdb make build
mv ./build/cronosd ./build/cronosd.exe
cd ./build
tar cvfz ../cronos.tar.gz *
cd ..
mv ./cronos.tar.gz cronos_${GITHUB_REF_NAME:1}-testnet_${PLATFORM}.tar.gz
ls -la cronos_*.tar.gz
sha256sum cronos_*.tar.gz > "checksums-$PLATFORM.txt"
echo "OK"
echo 'FILES<<EOF' >> $GITHUB_ENV
ls -1 *.tar.gz >> $GITHUB_ENV
ls -1 checksums-*.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
cat $GITHUB_ENV
- name: upload
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v1
with:
draft: true
files: "${{ env.FILES }}"
12 changes: 6 additions & 6 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
echo ${{ job.status }} > status_build.txt
- name: Upload file status_build.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_build
path: status_build.txt
Expand All @@ -146,7 +146,7 @@ jobs:
echo ${{ job.status }} > status_install.txt
- name: Upload file status_install.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_install
path: status_install.txt
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:
echo ${{ job.status }} > status_sim1.txt
- name: Upload file status_sim1.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_sim1
path: status_sim1.txt
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
echo ${{ job.status }} > status_sim2.txt
- name: Upload file status_sim2.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_sim2
path: status_sim2.txt
Expand Down Expand Up @@ -311,7 +311,7 @@ jobs:
echo ${{ job.status }} > status_sim3.txt
- name: Upload file status_sim3.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_sim3
path: status_sim3.txt
Expand Down Expand Up @@ -366,7 +366,7 @@ jobs:
echo ${{ job.status }} > status_sim4.txt
- name: Upload file status_sim4.txt as an artifact
if: github.event_name == 'issue_comment'
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: pass_status_sim4
path: status_sim4.txt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: 'Tar debug files'
if: failure()
run: tar cfz debug_files.tar.gz -C "${TMPDIR-/tmp}/pytest-of-runner" .
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: failure()
with:
name: debug-files
Expand Down
Loading

0 comments on commit 65d7297

Please sign in to comment.