Commit b2f52652 authored by Valentin Gagarin's avatar Valentin Gagarin Committed by fricklerhandwerk
Browse files

emscripten docs: reformat examples to use admonition

that way the examples will also appear in the appendix

Co-authored by: Henrik Karlsson <i97henka@gmail.com>
parent dd54e58c
Loading
Loading
Loading
Loading
+128 −113
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ A few things to note:
* `export EMCC_DEBUG=2` is nice for debugging
* The build artifact cache in `~/.emscripten` sometimes creates issues and needs to be removed from time to time

## Declarative usage {#declarative-usage}
## Examples {#declarative-usage}

Let's see two different examples from `pkgs/top-level/emscripten-packages.nix`:

@@ -27,10 +27,18 @@ This means each Emscripten package requires that a [`checkPhase`](#ssec-check-ph
* The cache at `~/.emscripten` requires to set `HOME=$TMPDIR` in individual phases.
  This makes compilation slower but also more deterministic.

::: {.example #usage-1-pkgs.zlib.override}

See the `zlib` example:
# Using `pkgs.zlib.override {}`

    zlib = (pkgs.zlib.override {
This example uses `zlib` from Nixpkgs, but instead of compiling **C** to **ELF** it compiles **C** to **JavaScript** since we were using `pkgs.zlib.override` and changed `stdenv` to `pkgs.emscriptenStdenv`.

A few adaptions and hacks were put in place to make it work.
One advantage is that when `pkgs.zlib` is updated, it will automatically update this package as well.


```nix
(pkgs.zlib.override {
  stdenv = pkgs.emscriptenStdenv;
}).overrideAttrs
(old: rec {
@@ -82,13 +90,17 @@ See the `zlib` example:
      --replace 'AR="libtool"' 'AR="ar"' \
      --replace 'ARFLAGS="-o"' 'ARFLAGS="-r"'
  '';
    });
})
```

### Usage 2: pkgs.buildEmscriptenPackage {#usage-2-pkgs.buildemscriptenpackage}
:::{.example #usage-2-pkgs.buildemscriptenpackage}

This `xmlmirror` example features a emscriptenPackage which is defined completely from this context and no `pkgs.zlib.override` is used.
# Using `pkgs.buildEmscriptenPackage {}`

    xmlmirror = pkgs.buildEmscriptenPackage rec {
This `xmlmirror` example features an Emscripten package that is defined completely from this context and no `pkgs.zlib.override` is used.

```nix
pkgs.buildEmscriptenPackage rec {
  name = "xmlmirror";

  buildInputs = [ pkg-config autoconf automake libtool gnumake libxml2 nodejs openjdk json_c ];
@@ -137,9 +149,12 @@ This `xmlmirror` example features a emscriptenPackage which is defined completel
  checkPhase = ''

  '';
    };
}
```

:::

### Declarative debugging {#declarative-debugging}
## Debugging {#declarative-debugging}

Use `nix-shell -I nixpkgs=/some/dir/nixpkgs -A emscriptenPackages.libz` and from there you can go trough the individual steps. This makes it easy to build a good `unit test` or list the files of the project.