You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The `cosmocc` compiler is now being distributed as a self-contained
toolchain that's path-agnostic and it no longer requires you clone the
Cosmop repo to use it. The bin/ folder has been deleted from the mono
repo. The `fatcosmocc` command has been renamed to `cosmocc`. MacOS
support now works very well.
You can run your ELF AARCH64 executable on Apple Silicon as follows:
155
-
156
-
```sh
157
-
ape ./llama.com
158
-
```
159
-
160
-
If you want to run the `MODE=aarch64` unit tests, you need to have
161
-
qemu-aarch64 installed as a binfmt_misc interpreter. It needs to be a
162
-
static binary if you want it to work with Landlock Make's security. You
163
-
can use the build included in our `third_party/qemu/` folder.
164
-
165
-
```
166
-
doas cp o/third_party/qemu/qemu-aarch64 /usr/bin/qemu-aarch64
167
-
doas sh -c "echo ':qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:CF' > /proc/sys/fs/binfmt_misc/register"
168
-
make -j8 m=aarch64
169
-
```
170
-
171
-
Please note that the qemu-aarch64 binfmt_misc interpreter installation
172
-
process is *essential* for being able to use the `aarch64-unknown-cosmo`
173
-
toolchain to build fat APE binaries on your x86-64 machine.
174
-
175
-
## AMD64 + ARM64 fat APE binaries
176
-
177
-
If you've setup the qemu binfmt_misc interpreter, then you can can use
178
-
cosmo's toolchains to build fat ape binaries. It works by compiling your
179
-
program twice, so you can have a native build for both architectures in
180
-
the same file. The two programs are merged together by apelink.com which
181
-
also embeds multiple copies of APE loader and multiple symbols tables.
182
-
183
-
The easiest way to build fat APE is using `fatcosmocc`. This compiler
184
-
works by creating a concomitant `.aarch64/foo.o` for every `foo.o` you
185
-
compile. The only exception is the C preprocessor mode, which actually
186
-
runs x86-64 GCC except with macros like `__x86_64__` undefined.
187
-
188
-
This toolchain works great for C projects that are written in a portable
189
-
way and don't produce architecture-specific artifacts. One example of a
190
-
large project that can be easily built is GNU coreutils.
191
-
192
-
```sh
193
-
cd coreutils
194
-
fatcosmocc --update ||exit
195
-
./configure CC=fatcosmocc \
196
-
AR=fatcosmoar \
197
-
INSTALL=$(command -v fatcosmoinstall) \
198
-
--prefix=/opt/cosmos \
199
-
--disable-nls \
200
-
--disable-dependency-tracking \
201
-
--disable-silent-rules
202
-
make -j8
203
-
```
204
-
205
-
You'll then have a bunch of files like `src/ls` which are fat ape
206
-
binaries. If you want to run them on Windows, then you simply need to
207
-
rename the file so that it has the `.com` suffix. Better yet, consider
208
-
making that a symlink (a.k.a. reparse point). The biggest gotcha with
209
-
`fatcosmocc` though is ensuring builds don't strip binaries. For
210
-
example, Linux's `install -s` command actually understands Windows'
211
-
Portable Executable format well enough to remove the MS-DOS stub, which
212
-
is where the APE shell script is stored. You need to ensure that
213
-
`fatcosmoinstall` is used instead. Especially if your project needs to
214
-
install the libraries built by `fatacosmoar` into `/opt/cosmos`.
215
-
216
-
## Advanced Fat APE Builds
217
-
218
-
Once you get seriously involved in creating fat APE builds of software
219
-
you're going to eventually outgrow `fatcosmocc`. One example is Emacs
220
-
which is trickier to build, because it produces architecture-specific
221
-
files, and it also depends on shared files, e.g. zoneinfo. Since we like
222
-
having everything in a neat little single-file executable container that
223
-
doesn't need an "installation wizard", this tutorial will explain how we
224
-
manage to accomplish that.
225
-
226
-
What you're going to do is, instead of using `fatcosmocc`, you're going
227
-
to use both the `x86_64-unknown-cosmo-cc` and `aarch64-unknown-cosmo-cc`
228
-
toolchains independently, and then run `apelink` and `zip` to manually
229
-
build the final files. But there's a few tricks to learn first.
230
-
231
-
The first trick is to create a symlink on your system called `/zip`.
232
-
Cosmopolitan Libc normally uses that as a synthetic folder that lets you
233
-
access the assets in your zip executable. But since that's a read-only
234
-
file system, your build system should use the normal one.
235
-
236
-
```sh
237
-
doas ln -sf /opt/cosmos /zip
61
+
./hello --ftrace
238
62
```
239
63
240
-
Now create a file named `rebuild-fat.sh` which runs the build twice:
64
+
You can use the Cosmopolitan's toolchain to build conventional open
65
+
source projects which use autotools. This strategy normally works:
241
66
242
67
```sh
243
-
#!/bin/sh
244
-
set -ex
245
-
export MODE=aarch64
246
-
export COSMOS=/opt/cosmos/aarch64
247
-
rebuild-cosmos.sh aarch64
248
-
export MODE=
249
-
export COSMOS=/opt/cosmos/x86_64
250
-
rebuild-cosmos.sh x86_64
251
-
wall.com 'finished building'
252
-
```
253
-
254
-
Then create a second file `rebuild-cosmos.sh` which runs your build:
0 commit comments