<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/55786>55786</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            wasm-ld should ignore .rlib files in archives
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          hoodmane
      </td>
    </tr>
</table>

<pre>
    As per the rust issue https://github.com/rust-lang/rust/issues/80775, if you try to build an empty rust file:
```sh
rustc \ 
        -C target-feature=+mutable-globals \
        -C relocation-model=pic \
        -C link-args='-s SIDE_MODULE' \
        --target wasm32-unknown-emscripten \
        --crate-type cdylib \
        test.rs
```
the result is the following error:
```sh
note: wasm-ld: error: unknown file type: lib.rmeta
```
Rust libraries contain an index file called `lib.rmeta`. The linker is expected to ignore them. I can work around this with the following patch to the linker:

https://github.com/pyodide/pyodide/pull/2378/files#diff-c21c39739d2d98d34e3063aceea3d659b11bc10471c403a0199a5bc01587e58b

<details>
<summary>Emscripten linker patch</summary>

```py
if any(arg.endswith(".rlib") for arg in cmd):
  from tempfile import mkstemp
  from pathlib import Path
  tempfiles = []
  new_cmd = []
  try:
    for arg in cmd:
      if arg == "-lc":
        continue
      if not arg.endswith(".rlib"):
        new_cmd.append(arg)
        continue
      fd, temp_path = mkstemp()
      shutil.copy2(arg, temp_path)
      tempfiles.append(Path(temp_path))
      subprocess.call(["ar", "-d", temp_path, "lib.rmeta"])
      subprocess.call(["emranlib", temp_path])
      new_cmd.append(temp_path)
    cmd = new_cmd
    cmd = get_command_with_possible_response_file(cmd)
    check_call(cmd)
  finally:
    for file in tempfiles:
      file.unlink()
else:
  cmd = get_command_with_possible_response_file(cmd)
  check_call(cmd)
```
</details>

xref Pyodide PR https://github.com/pyodide/pyodide/pull/2378/

@sbc100
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVtuOozg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