Skip to content

Commit

Permalink
Problem: cross-compiling don't work
Browse files Browse the repository at this point in the history
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 (crypto-org-chain#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
  • Loading branch information
yihuang committed Feb 22, 2023
1 parent bbb8150 commit ff5a80d
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 2,190 deletions.
48 changes: 46 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,50 @@ jobs:
COSMOS_BUILD_OPTIONS=rocksdb make build
if: steps.changed-files.outputs.any_changed == 'true'
cross-build:
strategy:
fail-fast: false
matrix:
host: [aarch64-multiplatform, mingwW64, aarch64-darwin]
include:
- os: ubuntu-latest
- host: aarch64-darwin
os: 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 }}
- id: changed-files
uses: tj-actions/changed-files@v34
with:
files: |
*.go
*.mod
*.sum
- 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
env:
HOST: ${{ matrix.host }}
run: |
BUILD=$(nix eval --impure --raw --expr 'builtins.currentSystem')
nix build .#legacyPackages.${BUILD}.pkgsCross.${HOST}.cronos-matrix.cronosd-tarball
if: steps.changed-files.outputs.any_changed == 'true'
- uses: actions/upload-artifact@v3
with:
name: "cronosd-tarball-${{ matrix.host }}"
path: result
if-no-files-found: ignore

unittest:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -116,7 +160,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 +203,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
114 changes: 47 additions & 67 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ jobs:
- name: build and upload goreleaser binaries
run: make release

x86_64:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
linux:
needs: ["goreleaser"]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
environment: release
steps:
- uses: actions/checkout@v3
Expand All @@ -38,95 +35,98 @@ jobs:
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 }}

- name: build linux x86_64/arm64 binaries
run: |
PLATFORM="$(uname -s)_x86_64"
BUILD_TYPE="tarball"
FLAKE="github:${GITHUB_REPOSITORY}/${GITHUB_REF_NAME}"
BASEURL="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"
ARCH=$2
PKG="cronosd${NETWORK}-${BUILD_TYPE}"
if [ "$ARCH" == "arm64" ]; then
FLAKE="${BASEURL}#legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform.cronos-matrix.${PKG}"
else
cp result "$OUTPUT.tar.gz"
FLAKE="${BASEURL}#${PKG}"
fi
nix build -L "$FLAKE"
cp result "cronos_${GITHUB_REF_NAME:1}${NETWORK}_Linux_${ARCH}.tar.gz"
}
build ""
build "-testnet"
build "" "x86_64"
build "-testnet" "x86_64"
build "" "arm64"
build "-testnet" "arm64"
nix-env -i coreutils -f '<nixpkgs>'
sha256sum *.tar.gz > "checksums-$PLATFORM.txt"
sha256sum *.tar.gz > "checksums-Linux.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 linux x86_64/arm64 binaries
uses: softprops/action-gh-release@v1
with:
draft: true
files: "${{ env.FILES }}"

aarch64-linux:
macos:
needs: ["goreleaser"]
runs-on: ubuntu-latest
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 mac x86_64 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: |
PLATFORM="$(uname -s)_x86_64"
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
build() {
NETWORK=$1
nix build -L "${FLAKE}#cronosd${NETWORK}-${BUILD_TYPE}"
OUTPUT="cronos_${GITHUB_REF_NAME:1}${NETWORK}_${PLATFORM}"
./scripts/codesign_macos.sh ./result
mv signed.tar.gz "$OUTPUT.tar.gz"
}
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 ""
build "-testnet"
sha256sum *.tar.gz > checksums-$PLATFORM.txt
nix-env -i coreutils -f '<nixpkgs>'
sha256sum *.tar.gz > "checksums-$PLATFORM.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 mac x86_64 binaries
uses: softprops/action-gh-release@v1
with:
draft: true
Expand All @@ -144,36 +144,16 @@ jobs:
- name: setup msys2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
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
install: git msys2-devel base-devel mingw-w64-x86_64-gcc 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
./scripts/build-windows.sh
./build/cronosd.exe version --long
cd ./build
tar cvfz ../cronos.tar.gz *
cd ..
Expand Down
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
1 change: 1 addition & 0 deletions app/versiondb_placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// FIXME dummy change to trigger workflows
func setupVersionDB(
homePath string,
app *baseapp.BaseApp,
Expand Down
10 changes: 8 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib
, stdenv
, buildGoApplication
, nix-gitignore
, coverage ? false # https://tip.golang.org/doc/go1.20#cover
Expand All @@ -9,7 +10,7 @@
let
version = "v1.0.4";
pname = "cronosd";
tags = [ "ledger" "netgo" network "rocksdb" "grocksdb_clean_link" ];
tags = [ "ledger" "netgo" network "rocksdb" "grocksdb_no_link" ];
ldflags = lib.concatStringsSep "\n" ([
"-X github.com/cosmos/cosmos-sdk/version.Name=cronos"
"-X github.com/cosmos/cosmos-sdk/version.AppName=${pname}"
Expand Down Expand Up @@ -38,11 +39,16 @@ buildGoApplication rec {
subPackages = [ "cmd/cronosd" ];
buildFlags = lib.optionalString coverage "-cover";
CGO_ENABLED = "1";
CGO_LDFLAGS =
if stdenv.hostPlatform.isWindows
then "-lrocksdb-shared"
else "-lrocksdb -pthread -lstdc++ -ldl";

doCheck = false;
meta = with lib; {
description = "Official implementation of the Cronos blockchain protocol";
homepage = "https://cronos.org/";
license = licenses.asl20;
mainProgram = "cronosd";
mainProgram = "cronosd" + stdenv.hostPlatform.extensions.executable;
};
}
Loading

0 comments on commit ff5a80d

Please sign in to comment.