Skip to content

Commit 258b89a

Browse files
committed
Cross compilation Dockerfile and CMake toolchains
- Added Dockerfile based on Ubuntu Noble - Build dependencies for cross compiling C/C++ - Added CMake toolchain files to set compilers and flags for cross compilation targets. - Added CI based on GitHub actions to build, test and publish the docker image. - Uses unzipped source-code FMU from OpenModelica with some modifications, based on omc v1.26.0-dev. - Added OSMC license
0 parents  commit 258b89a

File tree

269 files changed

+112244
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+112244
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
3+
{
4+
"name": "def_container_crossbuild:latest",
5+
6+
"build": {
7+
"dockerfile": "../../Dockerfile"
8+
},
9+
10+
// Additional VSCode extensions
11+
"customizations": {
12+
"vscode": {
13+
"extensions": [
14+
"ms-vscode.cpptools-extension-pack"
15+
]
16+
}
17+
},
18+
19+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
20+
"remoteUser": "ubuntu"
21+
}

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Mark the generated FMU_Interaction1 resources as generated/ignored for diffs
2+
# - linguist-generated=true: tells GitHub linguist this is generated code
3+
# - export-ignore: exclude from archive exports
4+
# - -diff: disable textual diffs for these files
5+
6+
# Match all files under the FMU_Interaction1 directory
7+
test/resources/FMU_Interaction1/** linguist-generated=true export-ignore -diff
8+
9+
# Also match the directory itself (some tools may reference the directory path)
10+
test/resources/FMU_Interaction1/ linguist-generated=true export-ignore -diff

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
6+
- package-ecosystem: "github-actions"
7+
directory: "/"
8+
schedule:
9+
# Check for updates to GitHub Actions every week
10+
interval: "monthly"

.github/workflows/build.yml

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
name: Build Docker Image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'releases/**'
8+
pull_request:
9+
branches:
10+
- main
11+
- 'releases/**'
12+
13+
jobs:
14+
build:
15+
name: Build Docker image
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 60
18+
steps:
19+
- name: Check out the repo
20+
uses: actions/checkout@v5
21+
22+
- name: Extract metadata (tags, labels) for Docker
23+
id: meta
24+
uses: docker/metadata-action@v5
25+
with:
26+
# Use GitHub Container Registry (ghcr) so the image can be pushed from the workflow
27+
images: ghcr.io/OpenModelica/crossbuild
28+
29+
- name: Log in to GitHub Container Registry
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Build and push Docker image
37+
id: build-image
38+
uses: docker/build-push-action@v6
39+
with:
40+
context: .
41+
file: ./Dockerfile
42+
push: true
43+
tags: ${{ steps.meta.outputs.tags }}
44+
45+
outputs:
46+
image: ${{ steps.meta.outputs.tags }}
47+
48+
test-compile:
49+
name: Test Docker image across toolchains
50+
needs: build
51+
runs-on: ubuntu-latest
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
include:
56+
- toolchain: i686-linux-gnu
57+
fmi_platform_tuple: linux32
58+
lib_extension: so
59+
- toolchain: x86_64-linux-gnu
60+
fmi_platform_tuple: linux64
61+
lib_extension: so
62+
- toolchain: i686-w64-mingw32
63+
fmi_platform_tuple: win32
64+
lib_extension: dll
65+
- toolchain: x86_64-w64-mingw32
66+
fmi_platform_tuple: win64
67+
lib_extension: dll
68+
timeout-minutes: 15
69+
steps:
70+
- name: Check out the repo
71+
uses: actions/checkout@v5
72+
73+
- name: Log in to GitHub Container Registry
74+
uses: docker/login-action@v3
75+
with:
76+
registry: ghcr.io
77+
username: ${{ github.actor }}
78+
password: ${{ secrets.GITHUB_TOKEN }}
79+
80+
- name: Pull image pushed by build job
81+
shell: bash
82+
run: |
83+
docker pull "${{ needs.build.outputs.image }}"
84+
85+
- name: Test cross-compilation for matrix toolchain
86+
shell: bash
87+
env:
88+
TOOLCHAIN: ${{ matrix.toolchain }}
89+
FMI_PLATFORM_TUPLE: ${{ matrix.fmi_platform_tuple }}
90+
LIB_EXTENSION: ${{ matrix.lib_extension }}
91+
run: |
92+
docker run --rm \
93+
-v "${{ github.workspace }}":/work \
94+
-w /work \
95+
"${{ needs.build.outputs.image }}" \
96+
bash -lc "\
97+
cmake -S test/resources/FMU_Interaction1/sources \
98+
-B test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} \
99+
-DFMI_INTERFACE_HEADER_FILES_DIRECTORY=/work/test/resources/fmi \
100+
-DCMAKE_TOOLCHAIN_FILE=/opt/cmake/toolchain/${TOOLCHAIN}.cmake && \
101+
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target install && \
102+
test -f test/resources/FMU_Interaction1/binaries/${FMI_PLATFORM_TUPLE}/Interaction1.${LIB_EXTENSION} && \
103+
cmake --build test/resources/FMU_Interaction1/sources/build_${TOOLCHAIN} --target create_fmu"
104+
105+
- name: Upload Interaction1.fmu
106+
uses: actions/upload-artifact@v5
107+
with:
108+
name: Interaction1-${{ matrix.toolchain }}
109+
path: test/resources/Interaction1.fmu
110+
if-no-files-found: error
111+
112+
test-import:
113+
name: Test FMU import across systems
114+
needs: test-compile
115+
runs-on: ${{ matrix.os }}
116+
strategy:
117+
fail-fast: false
118+
matrix:
119+
include:
120+
- os: ubuntu-latest
121+
fmu_artifact: Interaction1-x86_64-linux-gnu
122+
- os: windows-latest
123+
fmu_artifact: Interaction1-x86_64-w64-mingw32
124+
125+
timeout-minutes: 30
126+
steps:
127+
- name: Download Interaction1.fmu
128+
uses: actions/download-artifact@v5
129+
with:
130+
name: ${{ matrix.fmu_artifact }}
131+
132+
- name: Install OMSimulator
133+
uses: OpenModelica/[email protected]
134+
with:
135+
version: '1'
136+
packages: |
137+
'omc'
138+
'omsimulator'
139+
140+
- name: Simulate 64-bit Linux FMU
141+
if: runner.os == 'Linux'
142+
shell: bash
143+
run: OMSimulator Interaction1.fmu
144+
145+
- name: Simulate 64-bit Windows FMU
146+
if: runner.os == 'Windows'
147+
run: OMSimulator.exe Interaction1.fmu

.github/workflows/publish.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish Docker Image
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
push_to_registry:
9+
name: Push Docker image to Docker Hub
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 60
12+
steps:
13+
- name: Check out the repo
14+
uses: actions/checkout@v5
15+
16+
- name: Log in to Docker Hub
17+
uses: docker/login-action@v3
18+
with:
19+
username: ${{ secrets.DOCKERHUB_USERNAME }}
20+
password: ${{ secrets.DOCKERHUB_TOKEN }}
21+
22+
- name: Extract metadata (tags, labels) for Docker
23+
id: meta
24+
uses: docker/metadata-action@v5
25+
with:
26+
images: OpenModelica/crossbuild
27+
28+
- name: Build and push Docker image
29+
uses: docker/build-push-action@v6
30+
with:
31+
context: .
32+
file: ./Dockerfile
33+
push: true
34+
tags: ${{ steps.meta.outputs.tags }}
35+
labels: ${{ steps.meta.outputs.labels }}

.vscode/launch.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "(gdb) Launch omc",
9+
"type": "cppdbg",
10+
"request": "launch",
11+
"program": "/home/USER/workdir/OpenModelica/build_cmake/install_cmake/bin/omc",
12+
"args": [
13+
"genFMUResources.mos"
14+
],
15+
"stopAtEntry": false,
16+
"cwd": "${workspaceFolder}/test",
17+
"environment": [],
18+
"externalConsole": false,
19+
"MIMode": "gdb",
20+
"setupCommands": [
21+
{
22+
"description": "Enable pretty-printing for gdb",
23+
"text": "-enable-pretty-printing",
24+
"ignoreFailures": true
25+
},
26+
{
27+
"description": "Set Disassembly Flavor to Intel",
28+
"text": "-gdb-set disassembly-flavor intel",
29+
"ignoreFailures": true
30+
},
31+
{
32+
"description": "Ignore power-fail (SIGPWR) in GDB: don't stop or print; still pass to program",
33+
"text": "-interpreter-exec console \"handle SIGPWR nostop noprint pass\"",
34+
"ignoreFailures": true
35+
},
36+
{
37+
"description": "Ignore CPU time limit exceeded (SIGXCPU) in GDB: don't stop or print; still pass to program",
38+
"text": "-interpreter-exec console \"handle SIGXCPU nostop noprint pass\"",
39+
"ignoreFailures": true
40+
}
41+
]
42+
}
43+
]
44+
}

Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG DIST=ubuntu:noble
2+
3+
FROM ${DIST}
4+
5+
LABEL maintainer="AnHeuermann"
6+
LABEL description="Cross-compile C FMUs for Linux and Windows"
7+
8+
COPY toolchain/ /opt/cmake/toolchain/
9+
10+
# Install build dependencies
11+
RUN apt-get update && apt-get install -y --no-install-recommends \
12+
binutils-mingw-w64 \
13+
build-essential \
14+
ca-certificates \
15+
clang \
16+
cmake \
17+
curl \
18+
g++ \
19+
g++-multilib \
20+
gcc \
21+
gcc-multilib \
22+
git \
23+
make \
24+
mingw-w64 \
25+
pkg-config \
26+
unzip \
27+
zip \
28+
&& rm -rf /var/lib/apt/lists/*

0 commit comments

Comments
 (0)