README.md 2.27 KB
Newer Older
Signum Temporis's avatar
Signum Temporis committed
1
2
# Docker for Free Pascal Compiler

3
Lightweight (Alpine based) Docker images for [Free Pascal](https://www.freepascal.org) Compiler with support for Linux and Windows targets (cross compilation).
Signum Temporis's avatar
Signum Temporis committed
4
5


6
7
8
9
10
11
12
13
14
15
16
## Image variants

* By target CPU / OS
  * `x86_64-linux`
  * `x86_64-win64` (cross compile)
* By size
  * `full` \
    Images containing all units.
  * `slim` \
    Images containing the following groups of units only: `fcl-base`, `rtl`, `rtl-console`, `rtl-objpas`.

17
18
## Building

19
### Build images
20
21
22
23
```console
make builds
```

24
### Tag images
25
26
27
28
```console
make tags
```

Signum Temporis's avatar
Signum Temporis committed
29
30
31
32
33
34
35
36
37
38
### Test tagged images
This needs [`bats`](https://github.com/bats-core/bats-core) to be on path.
```console
make tests
```
Alternatively, override `BATS` variable of `make`, i.e.:
```console
make tests BATS=/opt/bats-core/bin/bats
```

39
### Remove images
40
41
42
43
```console
make clean
```

44
### Remove tags
45
46
47
48
```console
make cleantags
```

49
## Usage of images
Signum Temporis's avatar
Signum Temporis committed
50

51
### Show FPC version
Signum Temporis's avatar
Signum Temporis committed
52
```console
53
docker run --rm signumtemporis/fpc:slim -iV
Signum Temporis's avatar
Signum Temporis committed
54
55
```

56
### Compile a file
57
_`hello.pas`_:
Signum Temporis's avatar
Signum Temporis committed
58
59
60
61
```console
begin
  writeln('Hello world!');
end.
62
63
```
```console
64
docker run --rm -v $(pwd):/workspace signumtemporis/fpc:slim hello.pas
Signum Temporis's avatar
Signum Temporis committed
65
66
```

67
### Cross compile to Win64
Signum Temporis's avatar
Signum Temporis committed
68
```console
69
docker run --rm -v $(pwd):/workspace signumtemporis/fpc:cross.x86_64-win64.slim hello.pas
Signum Temporis's avatar
Signum Temporis committed
70
71
```

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
### Extend slim image variant
This allows to add selected units keeping the image small.

***NOTE***: If You don't care about the image size then use the full variant directly.

The example below adds `hash` package.

Build custom image
```console
docker build -t my-fpc - <<<'
ARG VERSION=3.2.2

FROM signumtemporis/fpc:$VERSION-full AS full

FROM signumtemporis/fpc:$VERSION-slim
ARG VERSION
ARG FPC_UNITS_PATH=/usr/local/lib/fpc/$VERSION/units/x86_64-linux
COPY --from=full $FPC_UNITS_PATH/hash $FPC_UNITS_PATH/hash/
'
```

93
Prapare _`hello-md5.pas`_ file
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
```console
uses md5;
begin
  writeln(MD5Print(MD5String('Hello world!')));
end.
```

Compile
```console
docker run --rm -v $(pwd):/workspace my-fpc hello-md5.pas
```

If You run the `hello-md5` executable file then it should write `86fb269d190d2c85f6e0468ceca42a20` to the console. \
If You try to compile the same file using base slim image then You will get "*Can't find unit md5 used by Program*" error message.

Signum Temporis's avatar
Signum Temporis committed
109
110
111
## License

See the [LICENSE](LICENSE) file.