Skip to content

Commit

Permalink
add docker and cross compile for arm
Browse files Browse the repository at this point in the history
  • Loading branch information
devseed committed Nov 16, 2024
1 parent a682fc6 commit c4d8657
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 24 deletions.
69 changes: 51 additions & 18 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build linux x86, x64
name: build linux
on:
push: {tags: ['v*']} # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
Expand All @@ -7,39 +7,72 @@ permissions:
contents: write

jobs:
build_linux:
build_linux_local:
strategy:
matrix:
arch: [{prefix: x86_64, suffix: x64}, {prefix: i686, suffix: x86}]
arch: [{prefix: i386, suffix: x86}, {prefix: x86_64, suffix: x64}]

runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: init enviroment
run: |
if [ "${{ matrix.arch.prefix }}" = "i686" ]; then
sudo dpkg --add-architecture i386
sudo apt-get -y update
sudo apt-get -y install gcc-multilib g++-multilib gdb-multiarch
sudo apt-get -y install crossbuild-essential-i386
sudo apt-get -y install libc6:i386
sudo apt-get -y install libgtk-3-dev:i386 libx11-dev:i386
sudo mv -f /usr/bin/i386-linux-gnu-pkg-config /usr/bin/pkg-config
else
sudo apt-get -y install build-essential
sudo apt-get -y install libgtk-3-dev libx11-dev
fi
sudo apt-get -y install qemu-user-static binfmt-support
sudo apt-get -y install p7zip-full git cmake
- name: build ${{ matrix.arch.suffix }}
run: |
mkdir -p depend
source script/fetch_depend.sh
fetch_lua
fetch_wxwidgets
mkdir build
export DOCKER_ARCH=${{ matrix.arch.prefix }}
export BUILD_DIR=build
export BUILD_TYPE=MinSizeRel
bash script/build_docker.sh
- name: prepare release
run: |
mv build/TileViewer TileViewer_${{ github.ref_name }}_${{ matrix.arch.suffix }}_linux
- name: create release
uses: ncipollo/release-action@v1
if: github.event_name == 'push'
with:
artifacts: "TileViewer_*"
allowUpdates: "true"
token: ${{ secrets.GITHUB_TOKEN }}

build_linux_cross:
strategy:
matrix:
arch: [{prefix: armhf, suffix: arm32}, {prefix: aarch64, suffix: arm64}]

runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: init enviroment
run: |
sudo apt-get -y install qemu-user-static binfmt-support
sudo apt-get -y install p7zip-full git cmake
- name: build ${{ matrix.arch.suffix }}
run: |
mkdir -p depend
source script/fetch_depend.sh
fetch_lua
fetch_wxwidgets
mkdir build
export CC=${{ matrix.arch.prefix }}-linux-gnu-gcc
export CXX=${{ matrix.arch.prefix }}-linux-gnu-g++
export DOCKER_ARCH=${{ matrix.arch.prefix }}
export BUILD_DIR=build
export BUILD_TYPE=MinSizeRel
bash script/build_linux.sh
export USE_BUILDX=1
bash script/build_docker.sh
- name: prepare release
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_win.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: build windows x86, x64
name: build windows
on:
push: {tags: ['v*']} # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ endfunction()

# global config
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(CMAKE_C_COMPILER MATCHES i686) # multi arch for x86
if(CMAKE_C_COMPILER MATCHES i686 OR CMAKE_C_COMPILER MATCHES i386) # multi arch for x86
set(CMAKE_SYSTEM_LIBRARY_PATH /usr/lib/i386-linux-gnu) # this is very important
set(FIND_LIBRARY_USE_LIB64_PATHS OFF)
set(CMAKE_IGNORE_PATH /lib /usr/lib /usr/local/lib /usr/lib/x86_64-linux-gnu)
Expand Down
19 changes: 15 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tile Viewer

![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/yurisizuku/TileViewer?color=green&label=TileViewer)![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/TileViewer/build_win.yml?label=win(x86|x64)&style=flat-square) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/TileViewer/build_linux.yml?label=linux(x86|x64)&style=flat-square)
![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/yurisizuku/TileViewer?color=green&label=TileViewer)![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/TileViewer/build_win.yml?label=win(x86|x64)&style=flat-square) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/YuriSizuku/TileViewer/build_linux.yml?label=linux(x86|x64|arm32|arm64)&style=flat-square)

☘️ A cross platform tool to visulize and analyze texture (usually used for console game font) by tiles. It is inspired by `Crystal Tile 2`, and more flexible with custom lua script (for more complex situation, such as swizzle) and command line support. Also, it supports for droping file, save decoded image and show cursor moving in tiles.

Expand Down Expand Up @@ -201,20 +201,31 @@ sudo apt-get -y install libc6:armhf
sudo apt-get -y install libgtk-3-dev:armhf libx11-dev:armhf
```

then fetch depends and build
linux local build

``` sh
git clone https://github.com/YuriSizuku/TileViewer.git
cd TileViewer
chmod +x script/*.sh

# linu x64 debug
# linux x64 debug
export CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++ BUILD_DIR=build_linux64 BUILD_TYPE=Debug && bash script/build_linux.sh

# linux x86_release
export CC=i686-linux-gnu-gcc CXX=i686-linux-gnu-g++ BUILD_DIR=build_linux32 BUILD_TYPE=MinSizeRel && bash script/build_linux.sh
```

linux cross build by docker

``` sh
sudo apt-get -y install qemu-user-static binfmt-support

export DOCKER_ARCH=i386 BUILD_DIR=build_linux32_docker BUILD_TYPE=MinSizeRel && bash script/build_docker.sh
export DOCKER_ARCH=x86_64 BUILD_DIR=build_linux64_docker BUILD_TYPE=MinSizeRel && bash script/build_docker.sh
export DOCKER_ARCH=armhf BUILD_DIR=build_linuxa32_docker BUILD_TYPE=MinSizeRel USE_BUILDX=1 && bash script/build_docker.sh
export DOCKER_ARCH=aarch64 BUILD_DIR=build_linuxa64_docker BUILD_TYPE=MinSizeRel USE_BUILDX=1 && bash script/build_docker.sh
```

## Roadmap

* Core
Expand All @@ -235,7 +246,7 @@ export CC=i686-linux-gnu-gcc CXX=i686-linux-gnu-g++ BUILD_DIR=build_linux32 BUIL
* [x] use github action to auto build
* [x] llvm-mingw compile (x86, x64)
* [x] linux compile (x86, x64)
* [ ] linux cross compile by dockerx (arm32, arm64)
* [x] linux cross compile by docker (arm32, arm64)

## Issues

Expand Down
6 changes: 6 additions & 0 deletions script/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ARG DOCKER_ARCH
FROM --platform=${DOCKER_ARCH} debian:buster
RUN apt-get -y update \
&& apt-get -y install make cmake tar p7zip git wget curl \
&& apt-get -y install build-essential \
&& apt-get -y install libgtk-3-dev libx11-dev
30 changes: 30 additions & 0 deletions script/build_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PROJECT_HOME=$(pwd)
if [ -z "${DOCKER_ARCH}" ]; then
DOCKER_ARCH=x86_64
fi
DOKCER_FILE=script/Dockerfile
DOCKER_IMAGE=tileviewer_${DOCKER_ARCH}
DOCKER_RUN=${DOCKER_IMAGE}_run
DOCKER_HOME=/project

if [ -z "$USE_BUILDX" ]; then
docker_build="docker build"
else
docker_build="docker buildx build"
fi
echo "## DOCKER_ARCH=${DOCKER_ARCH}"
echo "## docker_build=${docker_build}"

if [ -z "$(docker images | grep ${DOCKER_IMAGE})" ]; then
$docker_build ./ --platform linux/${DOCKER_ARCH} \
--build-arg DOCKER_ARCH=${DOCKER_ARCH} \
-f ${DOKCER_FILE} -t ${DOCKER_IMAGE}
fi

if [ -z "$(docker ps | grep ${DOCKER_RUN})" ]; then
docker run -d -it --rm -v ${PROJECT_HOME}:${DOCKER_HOME} \
--name ${DOCKER_RUN} ${DOCKER_IMAGE}
fi

docker exec -i -e BUILD_TYPE=$BUILD_TYPE -e BUILD_DIR=$BUILD_DIR \
${DOCKER_RUN} bash -c "cd ${DOCKER_HOME}; bash script/build_linux.sh"

0 comments on commit c4d8657

Please sign in to comment.