Subject: Re: bazel-zig-cc + rust

From: Motiejus Jakštys <[email-masked]>
Date: Tue, 30 Aug 2022 06:07:18 +0300

On Tue, Aug 30, 2022 at 5:48 AM Kevin King <[email-masked]> wrote:
> Hi Motiejus,

Hi Kevin!

> Thank you for the awesome bazel integration! I wasn't sure how to reach out so let me know if there's a better way.

Use the mailing list. :)

> I am working on a bazel+rust+wasm project and was looking to use zig to cross-compile a rust web server to linux/{arm,amd}. The only problem I ran into with bazel-zig-cc was that the rust does not pass its env down to the linker process, and so the #!/usr/bin/env sh line fails. I was able to fix it by changing it to #!/bin/sh (and then everything worked perfectly!), but I understand that things like nix put sh elsewhere.

That was /usr/bin/bash originally, then /usr/bin/env bash, then I
removed the bashisms and changed to /usr/bin/env sh. Louis, does NixOS
suppot /bin/sh?

Kevin, why does /usr/bin/env sh fail? What is the error message?
That's quite curious, since that would imply /usr/bin/env does not
exist, or sh is not in $PATH.

> Can you think of any potential solutions that would work for both rust and nix?

Let's try to find out.

Motiejus

---

From: Motiejus Jakštys <[email-masked]>
Date: Tue, 30 Aug 2022 09:20:41 +0300

On Tue, Aug 30, 2022 at 6:58 AM Kevin King <[email-masked]> wrote:
>
> The error I get is
>
> linking with `/private/var/tmp/_bazel_kevin/c782d9784982eee1866a2e1ae5f6f353/external/zig_sdk/tools/c++` failed: exit status: 127
> [...]
>  = note: env: sh: No such file or directory
>
> This appears to mean /usr/bin/env is executed correctly, but env itself can't find sh. Linking succeeds when I change the zig wrapper to use /bin/sh directly, leading me to believe rust does not pass PATH down to the linker.

I asked in #zig:libera.chat, and Andrew pointed out that `/bin/sh` and
`/usr/bin/env` are the only two files in `/bin` and `/usr/bin`
respectively. So `#!/bin/sh` will work both NixOS and in your case,
since it's an absolute path.

I will make the change in bazel-zig-cc later today.

Motiejus

---

From: Kevin King <[email-masked]>
Date: Mon, 29 Aug 2022 23:22:37 -0700

Oh perfect! I'm glad there was a simple fix :)