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

Commit

Permalink
CI: Build for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mbitsnbites committed Nov 30, 2021
1 parent 1d1c272 commit 5ac7183
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 45 deletions.
136 changes: 98 additions & 38 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,52 @@ jobs:
build:
name: ${{ matrix.config.name }}
runs-on: ${{ matrix.config.os }}
defaults:
run:
shell: ${{ matrix.config.shell }}

strategy:
fail-fast: false
matrix:
config:
- {
name: "Ubuntu 20.04 AMD64",
name: "Ubuntu 20.04 x86_64",
os: ubuntu-20.04,
build_env: "docker",
shell: "bash",
build_type: "docker",
cc: "gcc",
cxx: "g++",
artifact: "mrisc32-gnu-toolchain-linux-amd64.tar.gz",
cflags: "-O2",
cxxflags: "-O2",
ldflags: "",
artifact: "mrisc32-gnu-toolchain-linux-x86_64.tar.gz",
archive_type: "tar",
}
- {
name: "macOS Latest",
name: "macOS x86_64",
os: macos-latest,
build_env: "native",
shell: "bash",
build_type: "native",
cc: "clang",
cxx: "clang++",
artifact: "mrisc32-gnu-toolchain-macos.zip",
archive_type: "zip"
cflags: "-O2",
cxxflags: "-O2",
ldflags: "",
artifact: "mrisc32-gnu-toolchain-macos-x86_64.zip",
archive_type: "zip",
}
- {
name: "Windows x86_64",
os: windows-latest,
shell: 'msys2 {0}',
build_type: "native",
cc: "x86_64-w64-mingw32-gcc",
cxx: "x86_64-w64-mingw32-g++",
cflags: "-O2",
cxxflags: "-O2",
ldflags: "-static -static-libgcc -static-libstdc++",
artifact: "mrisc32-gnu-toolchain-win-x86_64.zip",
archive_type: "zip",
}

steps:
Expand All @@ -41,47 +66,72 @@ jobs:
with:
submodules: recursive

- name: Build toolchain (with Docker)
if: ${{ matrix.config.build_env == 'docker' }}
run: |
./build-in-docker.sh
- name: Build toolchain (native)
if: ${{ matrix.config.build_env == 'native' }}
- name: Set up MSYS2 & MinGW
if: ${{ runner.os == 'Windows' }}
uses: msys2/setup-msys2@v2
with:
update: true
location: D:\
install: >-
mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config
autoconf automake bison bzip2 curl dos2unix flex
gawk gzip libzstd-devel make p7zip perl tar texinfo
- name: Build toolchain
env:
CC: "${{ matrix.config.cc }}"
CXX: "${{ matrix.config.cxx }}"
CFLAGS: "${{ matrix.config.cflags }}"
CXXFLAGS: "${{ matrix.config.cxxflags }}"
LDFLAGS: "${{ matrix.config.ldflags }}"
run: |
mkdir -p out/install
./build.sh --prefix=${PWD}/out/install --clean
- name: Prepare archive content
# Fix texi CR/LF issues ("...table requires an argument...").
if [ "${{ runner.os }}" == "Windows" ] ; then
find ./ext -iname "*.texi" -exec dos2unix -q '{}' \;
fi
if [ "${{ matrix.config.build_type }}" == "docker" ] ; then
./build-in-docker.sh
else
mkdir -p out/install
./build.sh --prefix=${PWD}/out/install --clean
fi
- name: Pack archive
run: |
mv out/install mrisc32-gnu-toolchain
# Add GPL license files.
cp ext/binutils-mrisc32/COPYING* mrisc32-gnu-toolchain/
cp ext/newlib-mrisc32/COPYING* mrisc32-gnu-toolchain/
cp ext/gcc-mrisc32/COPYING* mrisc32-gnu-toolchain/
- name: Pack tar archive
if: ${{ matrix.config.archive_type == 'tar' }}
run: |
tar -cvzf ${{ matrix.config.artifact }} mrisc32-gnu-toolchain
# Add required DLLs for Windows builds.
if [ "${{ runner.os }}" == "Windows" ] ; then
cp /d/msys64/mingw64/bin/libiconv-*.dll mrisc32-gnu-toolchain/bin/
cp /d/msys64/mingw64/bin/libcharset-*.dll mrisc32-gnu-toolchain/bin/
fi
- name: Pack zip archive
if: ${{ matrix.config.archive_type == 'zip' }}
run: |
7z a -tzip -mx=9 ${{ matrix.config.artifact }} mrisc32-gnu-toolchain
if [ "${{ matrix.config.archive_type }}" == "tar" ] ; then
tar -cv -I "gzip -9" -f ${{ matrix.config.artifact }} mrisc32-gnu-toolchain
else
7z a -tzip -mx=9 ${{ matrix.config.artifact }} mrisc32-gnu-toolchain
fi
- name: Upload
- name: Upload artifact
uses: actions/upload-artifact@v1
with:
path: ${{ matrix.config.artifact }}
name: ${{ matrix.config.artifact }}

release:
name: Release
if: contains(github.ref, 'tags/v')
runs-on: ubuntu-20.04
needs: build

steps:
- name: Create Release
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
Expand All @@ -92,32 +142,39 @@ jobs:
draft: false
prerelease: false

- name: Store Release url
- name: Store release URL
run: |
echo "${{ steps.create_release.outputs.upload_url }}" > ./upload_url
- uses: actions/upload-artifact@v1
- name: Upload release URL
uses: actions/upload-artifact@v1
with:
path: ./upload_url
name: upload_url

publish:
if: contains(github.ref, 'tags/v')
name: ${{ matrix.config.name }}
if: contains(github.ref, 'tags/v')
runs-on: ubuntu-20.04
needs: release

strategy:
fail-fast: false
matrix:
config:
- {
name: "Ubuntu 20.04 AMD64",
artifact: "mrisc32-gnu-toolchain-linux-amd64.tar.gz",
name: "Ubuntu 20.04 x86_64",
artifact: "mrisc32-gnu-toolchain-linux-x86_64.tar.gz",
artifact_content_type: "application/x-tar",
}
- {
name: "macOS Latest",
artifact: "mrisc32-gnu-toolchain-macos.zip",
name: "macOS x86_64",
artifact: "mrisc32-gnu-toolchain-macos-x86_64.zip",
artifact_content_type: "application/zip",
}
- {
name: "Windows x86_64",
artifact: "mrisc32-gnu-toolchain-win-x86_64.zip",
artifact_content_type: "application/zip",
}

Expand All @@ -128,16 +185,19 @@ jobs:
name: ${{ matrix.config.artifact }}
path: ./

- name: Download URL
- name: Download release URL
uses: actions/download-artifact@v1
with:
name: upload_url
path: ./
- id: set_upload_url

- name: Set upload URL
id: set_upload_url
run: |
upload_url=`cat ./upload_url`
echo ::set-output name=upload_url::$upload_url
- name: Upload to Release
- name: Upload artifact to release
id: upload_to_release
uses: actions/upload-release-asset@v1.0.1
env:
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ This is a top level repository for building the MRISC32 toolchain.

The latest pre-built version of the toolchain can be found [here](https://github.com/mrisc32/mrisc32-gnu-toolchain/releases/latest).

Binaries are available for:

* Linux (x86_64)
* macOS (x86_64)
* Windows (x86_64)

## Installation

1. Unpack the archive to a location of your choice.
2. Add `path/to/mrisc32-gnu-toolchain/bin` to your `PATH` environment variable (e.g. in `$HOME/.bashrc` on Linux).

# Building yourself

Currently there are two methods for building the toolchain:
Expand All @@ -15,19 +26,19 @@ Currently there are two methods for building the toolchain:

## Host build

The build has only been tested on Ubuntu 20.04, but may work on other similar systems too.
The build has been tested on Ubuntu 20.04 (with GCC), macOS (with clang) and Windows (with MSYS2 and MinGW), but may work on other similar systems too.

### Prerequities

The following packages are required:
The following packages are required (example given for Ubuntu):

```bash
sudo apt install bison build-essential curl flex texinfo zlib1g-dev
sudo apt install bison build-essential curl flex texinfo
```

### Building

To build and install the GNU toolchain for MRISC32, do:
To build and install the GNU toolchain for MRISC32, do (example given for Ubuntu):

```bash
git submodule update --init --recursive
Expand Down
46 changes: 44 additions & 2 deletions build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@
# 3. This notice may not be removed or altered from any source distribution.
##############################################################################

function help {
echo "Usage: $0 [options]"
echo ""
echo "Build the MRISC32 GNU toolchain inside a Docker container."
echo ""
echo "Options:"
echo " --arch=ARCH Set the docker architecture (default: amd64)"
echo " -h, --help Show this text"
echo ""
echo "Valid values for ARCH: amd64, arm64v8, arm32v7"
}

# Parse arguments.
ARCH=amd64
for arg in "$@" ; do
case $arg in
-h|--help)
help
exit 0
;;
--arch=*)
ARCH="${arg#*=}"
;;
*)
echo "*** Invalid argument: $arg"
help
exit 1
;;
esac
done

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

# Set up the installation folder.
Expand All @@ -29,8 +60,14 @@ _install_dir_host=${SCRIPT_DIR}/out/install
mkdir -p "${_install_dir_host}"

# Build the docker image.
_container_name=mrisc32-gnu-toolchain-builder
docker build -q -t ${_container_name} ${SCRIPT_DIR}/docker
_container_name=mrisc32-gnu-toolchain-builder-${ARCH/\//-}
echo "Building the container ${_container_name}"
docker build \
-q \
-t ${_container_name} \
--build-arg _cpu_arch="${ARCH}" \
${SCRIPT_DIR}/docker
echo ""

# Run the build inside the container.
_uid=$(id -u)
Expand All @@ -41,6 +78,11 @@ docker run \
-v "${_install_dir_host}":"${_install_dir}" \
-v "${SCRIPT_DIR}":/work \
-w /work \
-e CC="${CC:-cc}" \
-e CXX="${CXX:-c++}" \
-e CFLAGS="${CFLAGS:--O2}" \
-e CXXFLAGS="${CXXFLAGS:--O2}" \
-e LDFLAGS="${LDFLAGS:-}" \
${_container_name} \
./build.sh --prefix="${_install_dir}" --clean

1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ if [ "$BUILD_GCC" == "yes" ] ; then
--with-gnu-ld \
--disable-shared \
--disable-libssp \
--disable-libstdcxx-pch \
> "${LATEST_LOG}" 2>&1

echo " Building..."
Expand Down
4 changes: 3 additions & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM ubuntu:20.04
ARG _cpu_arch="amd64"

FROM ${_cpu_arch}/ubuntu:20.04

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
Expand Down

0 comments on commit 5ac7183

Please sign in to comment.