1
- FROM swift:5.7 as builder
1
+ ARG SWIFTVERSION=5.8.1
2
+ ARG UBUNTUDISTRO=jammy
2
3
3
- # Install native dependencies
4
+ FROM swift:${SWIFTVERSION}-${UBUNTUDISTRO} AS sysroot
5
+
6
+ WORKDIR /opt/d2
7
+
8
+ # Install build dependencies into target sysroot
4
9
COPY Scripts/install-build-dependencies-apt Scripts/
5
10
RUN Scripts/install-build-dependencies-apt && rm -rf /var/lib/apt/lists/*
6
11
7
- # Build
12
+ FROM --platform=$BUILDPLATFORM swift:${SWIFTVERSION}-${UBUNTUDISTRO} AS builder
13
+
14
+ ARG SWIFTVERSION
15
+ ARG UBUNTUDISTRO
16
+ ARG BUILDARCH
17
+ ARG TARGETARCH
18
+
19
+ ARG TARGETSYSROOT=/usr/local/${TARGETARCH}-ubuntu-${UBUNTUDISTRO}
20
+
8
21
WORKDIR /opt/d2
22
+
23
+ # Copy target sysroot into builder
24
+ # TODO: Only copy stuff that we need for compilation (/usr/lib, /usr/include etc.)
25
+ COPY --from=sysroot / ${TARGETSYSROOT}
26
+
27
+ # Install (cross-)GCC and patch some paths
28
+ COPY Scripts/prepare-docker-buildroot Scripts/get-linux-arch-name Scripts/
29
+ RUN Scripts/prepare-docker-buildroot
30
+
31
+ # (Cross-)compile D2
9
32
COPY Sources Sources
10
33
COPY Tests Tests
11
34
COPY Package.swift Package.resolved ./
12
- RUN swift build -c release
35
+ COPY Scripts/build-release Scripts/
36
+ RUN Scripts/build-release
37
+
38
+ FROM swift:${SWIFTVERSION}-${UBUNTUDISTRO}-slim AS runner
13
39
14
- FROM swift:5.7-slim as runner
40
+ ARG TARGETARCH
41
+ ARG UBUNTUDISTRO
42
+
43
+ ARG TARGETSYSROOT=/usr/local/${TARGETARCH}-ubuntu-${UBUNTUDISTRO}
15
44
16
45
# Install Curl, add-apt-repository and node package repository
17
46
RUN apt-get update && apt-get install -y curl software-properties-common && rm -rf /var/lib/apt/lists/*
@@ -21,6 +50,10 @@ RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
21
50
COPY Scripts/install-runtime-dependencies-apt Scripts/
22
51
RUN Scripts/install-runtime-dependencies-apt && rm -rf /var/lib/apt/lists/*
23
52
53
+ # Link 'sysroot' to / to make sure D2 can find the Swift stdlibs
54
+ # (the runpath within the D2 executable still points to its /usr/lib/swift)
55
+ RUN ln -s / ${TARGETSYSROOT}
56
+
24
57
WORKDIR /opt/d2
25
58
26
59
# Install Node dependencies
@@ -32,9 +65,13 @@ RUN Scripts/install-node-dependencies
32
65
COPY Resources Resources
33
66
COPY LICENSE README.md ./
34
67
68
+ ARG TARGETOS
69
+ ARG TARGETARCH
70
+
35
71
# Set up .build folder in runner
36
72
WORKDIR /opt/d2/.build
37
- RUN mkdir -p x86_64-unknown-linux-gnu/release && ln -s x86_64-unknown-linux-gnu/release release
73
+ COPY Scripts/setup-dotbuild-tree Scripts/
74
+ RUN Scripts/setup-dotbuild-tree
38
75
39
76
# Copy font used by swiftplot to the correct path
40
77
COPY --from=builder \
0 commit comments