# Simpler cross-compiling for multiple platforms

**URL:** https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456
**Category:** Questions & Answers
**Tags:** question, raco, cross, cross-compilation
**Created:** [December 20, 2021, 6:15pm UTC](https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456 "2021-12-20T18:15:25Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)
#### Post date: [December 20, 2021, 6:15pm UTC](https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456/1 "2021-12-20T18:15:25Z")

</div>

For a project of mine I use the following Makefile code to create binaries for different platforms:

```makefile
VERSION=$(shell cat VERSION)

TARGET ?= x86_64-linux
NICE_TARGET ?= ${TARGET}
VM ?= cs
# Both options are allowed for Posix and Windows.
TARGET_OPTS ?= --orig-exe --embed-dlls
# `raco exe` appends `.exe` for Windows automatically.
EXE_NAME := sudoku-solver-${VERSION}-${NICE_TARGET}
EXE_PATH := build/${NICE_TARGET}/${EXE_NAME}

# Build standalone binary.
.PHONY : build
build:
	mkdir -p "build/${NICE_TARGET}"
	# Ignore uninstalled package.
	-raco cross --target "${TARGET}" --vm ${VM} pkg remove sudoku-solver
	# Implicitly install dependencies.
	raco cross --target "${TARGET}" --vm ${VM} -j 4 pkg install --deps search-auto
	raco cross --target "${TARGET}" --vm ${VM} -j 4 exe ${TARGET_OPTS} \
		-o "${EXE_PATH}" games/sudoku-solver.rkt

.PHONY : build-x86_64-linux
build-x86_64-linux: build

.PHONY : build-x86_64-win32
build-x86_64-win32:
	TARGET=x86_64-win32 NICE_TARGET=x86_64-windows make build

.PHONY : build-x86_64-macosx
build-x86_64-macosx:
	TARGET=x86_64-macosx make build

.PHONY : build-aarch64-macosx
build-aarch64-macosx:
	TARGET=aarch64-macosx make build

# Create standalone binaries for different platforms.
.PHONY : build-all
build-all: build-x86_64-linux build-x86_64-win32 build-x86_64-macosx \
	build-aarch64-macosx

```

I run `make build-all` from the Git working directory root of my package.

I think it would make sense to make this more standalone, i.e. usable without Make, and of course independent of a specific hardcoded project and version. I could write a command line tool in Racket for this, but before I do it, I'd like to ask if you know of something like this that exists already. I'd like to avoid double work. 🙂

As for the packaging, I _guess_ the above is too specialized to be a part of `raco cross` or even a `raco` subcommand. So probably this should be a `raco pkg install`-able standalone script.

What do you think?

---

<div class="post-metadata">

### Author: ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)
#### Post date: [December 20, 2021, 7:34pm UTC](https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456/2 "2021-12-20T19:34:01Z")

</div>

> [@sschwarzer](#):
>
> As for the packaging, I _guess_ the above is too specialized to be a part of `raco cross` or even a `raco` subcommand. So probably this should be a `raco pkg install` -able standalone script.

I think it could be `raco pkg install`-able `raco` subcommand, but if that isn't desirable for some reason a standalone script works too.  
I am not aware of something that does this already, so far it has been on the back of my mind as something I might need eventually.

---

<div class="post-metadata">

### Author: ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)
#### Post date: [December 20, 2021, 8:44pm UTC](https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456/3 "2021-12-20T20:44:28Z")

</div>

> [@simonls](#):
>
> it has been on the back of my mind as something I might need eventually.

I think a way to easily generate standalone binaries also for other platforms is pretty important. Since Racket is used so little compared with mainstream languages, I assume it's unlikely that a non-Racketeer will install Racket for a command line program unless the program is _extremely_ interesting. 😉

---

<div class="post-metadata">

### Author: ![sschwarzer](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/sschwarzer/32/1940_2.png) [@sschwarzer](https://racket.discourse.group/u/sschwarzer)
#### Post date: [December 20, 2021, 9:47pm UTC](https://racket.discourse.group/t/simpler-cross-compiling-for-multiple-platforms/456/4 "2021-12-20T21:47:36Z")

</div>

I think I'll start with a standalone script and probably convert that to a raco subcommand later. I'm still not sure how to call the subcommand, though.

- `build-all` would relate to the use in the makefile, but it's easy to expect that the command will literally build all, for example a tarball and documentation.
- `exe-all` would be nice to hint at the similarity to `raco exe`, but my subcommand would actually do more, so the name might be misleading. But then, the functionality would be very similar to `raco exe`.
- `exe-multitarget`? This is a bit long, but I like that it's more explicit.
- Any other suggestions?
