# Migrating from 4x to 6x

This guide is for maintainers migrating existing emscripten-forge recipes from the **4x** channel to **6x** (Emscripten 6.0, with `emscripten-wasm32` and `emscripten-wasm64`).

Packages are published to [`emscripten-forge/6x`](https://prefix.dev/channels/@emscripten-forge/6x). Background on the 6x release and wasm64 is in the [blog post](../blog/posts/wasm64.md).

## Checklist

When migrating a recipe:

1. Move it into the correct directory (`recipes_wasm` or `recipes_native`).
2. Align package names with conda-forge.
3. Split static and shared libraries into separate outputs/packages.
4. Add `generic-testing`.
5. For shared libraries: add `run_exports`.
6. For `*-static` consumers: use `pin_compatible` and ensure `variant.yaml` pins exist.
7. Drop obsolete `SIDE_MODULE` / `WASM_BIGINT` workarounds for normal shared libraries.
8. Remove any `overwriteProp.cmake` from the recipe directory and use `${CMAKE_ARGS}` for CMake builds.
9. Update Fortran deps from `libflang` to `libflang-rt-static` where needed.
10. For `noarch: python`, adopt the `python_min` build/host/run pattern.

## Directory structure

Recipes must be **moved** (not copied) out of the legacy directories:

| Legacy (4x) | Canonical (6x) |
| --- | --- |
| `recipes/recipes` | `recipes/recipes_native` |
| `recipes/recipes_emscripten` | `recipes/recipes_wasm` |

`recipes_wasm` is the primary location for wasm packages. `recipes_emscripten` may still contain packages awaiting migration; do not add new recipes there.

## All packages

### Generic testing

All packages should include `generic-testing` in addition to any package-specific tests:

```yaml
tests:
- script: generic-testing
  requirements:
    build:
    - generic-testing
```

For `noarch: python` packages, set the target platform explicitly:

```yaml
tests:
- script: target_platform=${{ host_platform }} generic-testing
  requirements:
    build:
    - generic-testing
```

Some packages may need `generic-testing --allow-pthread` when ABI stubs trip the checker even though there is no real pthread activity (see `lxml`).

### Naming and library layout

- Package names should match [conda-forge](https://conda-forge.org/) when both ecosystems ship the same project (for example `libpcre2` / `libpcre2-static` / `pcre2` / `pcre2-static`).
- Packages must **not** contain both static and shared libraries in the same output. Split them into separate packages or recipe outputs (for example `geos` and `geos-static`). Shared-only or static-only packages are fine when only one flavour is needed.

## Shared libraries

- Packages that ship shared libraries must declare `run_exports`.
- On 6x, `-shared` / `BUILD_SHARED_LIBS=ON` produces real shared libraries. On 4x, `-shared` without `-sSIDE_MODULE=1` was often ignored.

Example `run_exports` pattern:

```yaml
requirements:
  build:
  - ${{ compiler('c') }}
  - ${{ compiler('cxx') }}
  run_exports:
  - ${{ pin_subpackage('geos', upper_bound='x.x') }}
```

## Static libraries

- Static library packages should end with `*-static` (for example `libfoo-static`).
- Run dependencies on `*-static` packages must use `pin_compatible`.
- Default pinning is `major.minor`, but always check [`variant.yaml`](https://github.com/emscripten-forge/recipes/blob/emscripten-6x/variant.yaml) for the pin in use.

```yaml
run:
- ${{ pin_compatible("libfoo-static", lower_bound='x.x', upper_bound='x.x') }}
```

Concrete example from `lxml`:

```yaml
host:
- libiconv-static
- libxml2-static
- libxslt-static
- zlib-static
run:
- ${{ pin_compatible("libiconv-static", lower_bound='x.x', upper_bound='x.x') }}
- ${{ pin_compatible("libxml2-static", lower_bound='x.x', upper_bound='x.x') }}
- ${{ pin_compatible("libxslt-static", lower_bound='x.x', upper_bound='x.x') }}
- ${{ pin_compatible("zlib-static", lower_bound='x.x', upper_bound='x.x') }}
```

## `variant.yaml`

- All `*-static` packages that need a global pin must have an entry in `variant.yaml`.
- The pin for a `*-static` package should match the pin for the non-static package when both exist.
- Default pin granularity is `major.minor` unless a different convention is already established for that package.

```yaml
zlib:
- 1.3
zlib-static:
- 1.3
libzlib:
- 1.3
libzlib-static:
- 1.3
```

## Wasm64

Both `emscripten-wasm32` and `emscripten-wasm64` are **enabled by default** in CI. You do not need to opt in per recipe.

Override `extra.ci.platforms` only when a package cannot (or should not) build for one of the platforms:

```yaml
extra:
  ci:
    platforms:
      emscripten-wasm32: true
      emscripten-wasm64: false
```

## Fortran

Packages that previously depended on `libflang` should depend on `libflang-rt-static` (and pin it with `pin_compatible` when it is a run dependency):

```yaml
host:
- libflang-rt-static
run:
- ${{ pin_compatible('libflang-rt-static', lower_bound='x.x', upper_bound='x.x') }}
```

Related packages may also ship as `libflang-rt` / `libflang-rt-headers`; prefer the static runtime for Fortran link deps unless a recipe specifically needs another output.

## Python

### `noarch: python`

Noarch Python packages relax the Python constraint per [CFEP-25](https://github.com/conda-forge/cfep/blob/main/cfep-25.md). Use:

```yaml
requirements:
  build:
  - python =${{ python_min }}
  host:
  - python =${{ python_min }}
  run:
  - python >=${{ python_min }}
```

Build against `python =${{ python_min }}` so files land in the matching `lib/pythonX.Y/site-packages`. Do **not** depend on an exact version + build string of other packages from noarch recipes.

## Flags and shared-library workarounds

For **normal shared library** packages:

- `WASM_BIGINT` is not needed anymore.
- Explicit `-sSIDE_MODULE=1` is not needed anymore; the compiler respects `-shared` properly.

## CMake

Delete `overwriteProp.cmake` / `overwriteProps.cmake` from the recipe directory, and remove any `-DCMAKE_PROJECT_INCLUDE=...` that pointed at it. Pass `${CMAKE_ARGS}` instead; the compiler activation already sets the necessary cross-compilation bits:

```bash
emcmake cmake ${CMAKE_ARGS} -S . -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON
```

## Known issue: libtool and wasm64

Autotools / libtool sometimes injects `-sSIDE_MODULE=2`. On wasm64 that can produce empty or incorrect shared libraries (effectively wasm32 stubs).

**Fix:** strip `-sSIDE_MODULE=2` from the libtool sources both before and after configure. See the `pcre2` build script:

```bash
# Remove this from the copied file and use -shared only
sed -i 's/-sSIDE_MODULE=2 //g' m4/libtool.m4

emconfigure ./configure \
    --prefix=$PREFIX \
    --host="$HOST" \
    --enable-shared \
    ...

# Needs to be removed again from the generated file
sed -i 's/-sSIDE_MODULE=2 //g' libtool
```

## Reference recipes

| Topic | Example under `recipes/recipes_wasm/` |
| --- | --- |
| Split shared / static outputs | `geos` |
| Shared `run_exports` + conda-forge naming | `pcre2`, `zlib` |
| `pin_compatible` on `*-static` | `lxml` |
| `CMAKE_ARGS` shared library | `xeus` |
| Fortran + `libflang-rt-static` | `slicot` |
| `noarch: python` + `python_min` | `zarr` |
| Disable wasm64 | `gthread-jspi` |
| libtool `SIDE_MODULE=2` cleanup | `pcre2` (`build.sh`) |
