Cross-compiler targeting macOS
Jacob Carlborg
doob at me.com
Wed Apr 7 12:24:40 UTC 2021
# Docker LDC Darwin
I would like to announce a new project I'm working on:
docker-ldc-darwin [1]. The project consists of a Dockerfile for
building a Docker image which has all the necessary tools to
cross-compile D applications targeting macOS x86-64.
## Features
* Uses Apple's ld64 linker so all features that are being used
when linking on macOS should work. No reliance on custom linkers
that need to be kept up to date with the system linker
* Ships with the full macOS SDK (for macOS version 10.15.4)
* No reliance on hacks like allowing undefined symbols when
linking like Zig and Rust does
* Minimal Docker image. Only the exact files that are required to
run the compiler and linker are included. Not even a shell is
included
* The Docker image, all tools and resources are fully
reproducible and automated. No manual steps involved of uploading
to random cloud storage accounts
The following tools are included:
* dub
* ldc2
* ldmd2
* rdmd
* ld64 (linker)
* clang (C compiler, used for linking)
## Building
### Prerequisites
* [git](https://git-scm.com)
* [Docker](https://www.docker.com)
### Building the Docker Image
Follow the steps below to build the Docker images by running the
commands in
the terminal:
1. Clone the git repository:
```
git clone
https://github.com/d-cross-compiler/docker-ldc-darwin && cd
docker-ldc-darwin
```
1. Build the Docker image:
```
docker build -t ldc-x86_64-apple-macos .
```
## Usage
By default, the `ldc2` compiler will be invoked.
### Compiling Hello World
Compile Hello World:
```
$ uname
Darwin
$ cat <<EOF > main.d
import std;
void main()
{
writeln("Hello World");
}
EOF
$ docker run --rm -v "$(pwd):/work" ldc-x86_64-apple-macos main.d
$ ./main
Hello World
```
For more information and examples, see the readme [1].
[1] https://github.com/d-cross-compiler/docker-ldc-darwin
--
/Jacob Carlborg
More information about the Digitalmars-d-announce
mailing list