0

I got in trouble with compilation of serenity Discord bot library. It compiles fine on Linux, but it fails on Windows with the following error:

error: environment variable `PATH_SEPARATOR` not defined
      --> C:\Users\my_user\.cargo\registry\src\github.com-1ecc6299db9ec823\proc-macro-nested-0.1.7\src\lib.rs:43:35
       |
    43 | include!(concat!(env!("OUT_DIR"), env!("PATH_SEPARATOR"), "count.rs"));
       |                                   ^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: this error originates in the macro `env` (in Nightly builds, run with -Z macro-backtrace for more info)

It used to work on Windows too, this error occurs since days only. When I define the environment variable as PATH_SEPARATOR=\ in the IDE (IntelliJ IDEA), the error is that the file on that path cannot be read (os error 2).
I tried to compile with msvc and gnu toolchains, but the error always appears.
No enviroment variables were needed to be set before, why do I need to set it now?

Tigers
  • 11
  • 5
  • 3
    My best guess is that the file `$OUT_DIR/count.rs` doesn't exist. – loa_in_ Sep 01 '21 at 18:26
  • @loa_in_ huh? the program doesn't even get as far as running, the compilation prevents it from running because the PATH_SEPARATOR variable is not set. The [env](http://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/std/macro.env.html) macro will resolve at compile time, before the (also compile time) include! resolves. – Félix Adriyel Gagnon-Grenier Sep 01 '21 at 18:32
  • It doesn't have to. `include!` fails at compilation time because `the file on that path cannot be read` as you said. – loa_in_ Sep 01 '21 at 18:33
  • @loa_in_ The include! is not resolved, is what I am saying. Also, the error message is rather clear... "error: environment variable `PATH_SEPARATOR` not defined". It's possible the file also does not exist, but that is not the situation that is causing the error here. – Félix Adriyel Gagnon-Grenier Sep 01 '21 at 18:34
  • The question was really unclear, I editod it. The problem actually is the need of setting this variable, because it wasn't required before. I tried to build from command line too, but the result was the same. – Tigers Sep 01 '21 at 18:47
  • Setting that variable in the IDE was for checking, "would it solve this error?" -- no, it leaded to another, which comes from the first, so the problem's root might be deeper. – Tigers Sep 01 '21 at 18:56
  • 2
    `PATH_SEPARATOR` is a Linux thing? This is the first time I'm hearing about it... and yep, it's not defined by any of the shells I have installed, and DuckDuckGo doesn't return anything particularly promising either. Why do you think this variable should be defined in the first place? – trent Sep 01 '21 at 19:02
  • 2
    For what it's worth, the culprit is the `proc-macro-nested` crate. It seems the [line in question](https://github.com/dtolnay/proc-macro-hack/blob/2f10e9de5ce68e9b04687a24b4ebe01bfc27e70e/nested/src/lib.rs#L43) was introduced in `v0.1.7` 8 months ago. – Herohtar Sep 01 '21 at 19:25
  • The only thing I can think of is that I updated Visual Studio. Before installing the update, it surely worked as intended, and now it doesn't. However, I can't find connection between these. – Tigers Sep 01 '21 at 19:27
  • I never set any enviroment variables before for `serenity` (just hit F9 for "Run project"), and it worked. – Tigers Sep 01 '21 at 19:35
  • So looking further into the code, the build script for `proc-macro-nested` sets that `PATH_SEPARATOR` environment variable to the platform-specific value, so you should never have to set it yourself. In that case, it makes no sense why it would suddenly start saying it is undefined. Are you just building with `cargo build`? – Herohtar Sep 01 '21 at 19:45
  • @Herohtar Thanks It must be the way to the root of the problem. I build the project with `cargo build --release`. I started programming in Rust in July. – Tigers Sep 01 '21 at 20:23
  • I updated everything in the last few days, I tried to solve it myself as best as I could. – Tigers Sep 01 '21 at 20:26
  • Guess we need to ask @dtolnay who wrote that code apparently as a workaround. – SirDarius Sep 01 '21 at 22:00

1 Answers1

0

You can try to set windows environment variable PATH_SEPARATOR to \ value from System Properties window as seen at https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/creating-and-modifying-environment-variables-on-windows.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0 Your IDE installation may prevent this edit, you may need administrator privileges for this action.

Stefan
  • 164
  • 1
  • 10
  • No, unfortunately it didn't solve the problem. – Tigers Sep 01 '21 at 18:57
  • Then it seems to look for the file $OUT_DIR/count.rs only, which you may find it on your old linux installation you mentioned it, copy it from there and and edit it, if it is a config file they usually are gitignored and you cannot just pull it from repo if so. – Stefan Sep 01 '21 at 20:19
  • This file is likely autogenerated, i.e. it is created by the previous compilation steps. – Cerberus Sep 02 '21 at 09:28