blt / port_compiler

A rebar3 port compiler
MIT License
65 stars 38 forks source link

Cannot compile on Erlang/OTP 27 #84

Closed SaphiraKai closed 1 month ago

SaphiraKai commented 1 month ago

I'm very unfamiliar with Erlang (I ran into this from a Gleam project), apologies if I confuse anything here.

I cannot compile pc on my machine when using Erlang/OTP 27:

$ rebar3 --version # rebar 3.23.0 on Erlang/OTP 27 Erts 15.0.1
$ rebar3 new lib project
$ cd project/
$ nano rebar.config # add `pc` to deps
$ rebar3 compile
===> Verifying dependencies...
===> Fetching pc v1.14.0
===> Analyzing applications...
===> Compiling pc
===> Compiling _build/default/lib/pc/src/pc_port_env.erl failed
_build/default/lib/pc/src/pc_port_env.erl:190:10: code:lib_dir/2 is deprecated; this functionality will be removed in a future release

Erlang/OTP 26 works:

$ rebar3 --version # rebar 3.23.0 on Erlang/OTP 26 Erts 14.2.5
$ rebar3 compile # after removing `_build` and `rebar.lock`
===> Verifying dependencies...
===> Fetching pc v1.14.0
===> Analyzing applications...
===> Compiling pc
===> Analyzing applications...
===> Compiling project
badlop commented 1 month ago

You are right, port_compiler 1.14 cannot be compiled using Erlang/OTP 27.

That was solved seven months ago in commit 7902cbeefaf18ce59878330b0f7bd946cc6ed963, and port_compiler 1.15 was released later. With that, port_compiler compiles perfectly with Erlang/OTP 27 and all the older versions :)

Let's see your case:

$ nano rebar.config # add `pc` to deps
...
$ rebar3 compile
===> Verifying dependencies...
===> Fetching pc v1.14.0

It seems you don't tell rebar3 what exact version of pc you want to install, so rebar3 searches its cache (in $HOME/.cache/rebar3/) if it has already downloaded one... and it seems you have downloaded pc 1.14 some time ago.

Solutions:

A) Tell rebar3 explicitely that you want to use pc 1.15, not any other. Maybe something like:

{pc, "1.15.0"}

B) Update your cached pc download. Looking at the documentation, I'd say something like this would help:

$ rebar3 plugins list
$ rebar3 plugins upgrade pc
tsloughter commented 1 month ago

Thanks @badlop! Definitely an annoying case of rebar3 not fetching the latest dep. It does this to not make network calls unless it has to, so if it a version in the cache matches the constraint in a config there is no update. Another way to "fix" this would have been:

rebar3 update

This updates the available versions in the local cache of hex packages. So it'd then know about pc 1.15.0. But if you had already run compile it would be "happily" using 1.14.0 and not update without an explicit change to the dep as @badlop shows or after cleaning out the plugins dir so it has to refetch pc.

SaphiraKai commented 1 month ago

Ahh, well that explains my test project at least.

It seems that a different project mine depends on (fs) is using the outdated version of pc, that's the real issue.

Thanks for the guidance!