zeam-vm / pelemay

Pelemay is a native compiler for Elixir, which generates SIMD instructions. It has a plan to generate for GPU code.
Apache License 2.0
187 stars 13 forks source link

/usr/include and /usr/lib may be disappeared in the case of macOS #80

Open zacky1972 opened 5 years ago

zacky1972 commented 5 years ago

Describe the bug

Error occurs when Clang compiled from the original site, not Apple Clang

To Reproduce Steps to reproduce the behavior:

  1. Use Pelemay in the source code in the pelemay_sample repository
  2. Run in the command 'mix bench' when it uses clang in /usr/local/bin
  3. See error
$ mix bench
Compiling 1 file (.ex)
In file included from /Users/zacky/github/pelemay_sample/_build/dev/lib/pelemay/priv/libnifelixirpelemaysample.c:3:
In file included from /Users/zacky/.asdf/installs/erlang/22.0.7/erts-10.4.4/include/erl_nif.h:31:
/Users/zacky/.asdf/installs/erlang/22.0.7/erts-10.4.4/include/erl_drv_nif.h:158:12: fatal error: 
      'sys/types.h' file not found
#  include <sys/types.h>
           ^~~~~~~~~~~~~
1 error generated.

== Compilation error in file lib/pelemay_sample.ex ==
** (MatchError) no match of right hand side value: {"", 1}
    lib/pelemay/generator/builder.ex:35: Pelemay.Generator.Builder.generate/1
    lib/pelemay.ex:51: Pelemay.pelemaystub/2
    expanding macro: Pelemay.defpelemay/1
    lib/pelemay_sample.ex:22: PelemaySample (module)

Expected behavior Compilation and benchmarking run successful.

Screenshots None.

Desktop (please complete the following information):

$ clang --version
clang version 10.0.0 (https://github.com/llvm/llvm-project.git 078bec6c48dd9d17ab9720897d2bb7ccbb886763)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /usr/local/bin

Additional context Compilation options may be wrong.

zacky1972 commented 5 years ago

This problem is fixed according to this: https://qiita.com/yoya/items/630c991a98e4554e6e87

I guess Pelemay should check whether /usr/include exists or not on Mac OS. If not, Pelemay should put a message to reinstall command line tools at that directory.

zacky1972 commented 4 years ago

I found this article: https://qiita.com/yoya/items/c0b26cba3c040c581643

This said, /usr/include is deprecated by Catalina and Xcode 11.

zacky1972 commented 4 years ago

The code

{usr_include_org, usr_lib_org} = {"/usr/include", "/usr/lib"}
{usr_include, usr_lib} =
  case :os.type() do
    {:unix, :darwin} ->
      if is_nil(System.find_executable("xcrun")) do
        {usr_include_org, usr_lib_org}
      else
        {result, error_code} = System.cmd("xcrun", ["--sdk", "macosx", "--show-sdk-path"])
        if error_code != 0 do
          {usr_include_org, usr_lib_org}
        else 
          p = result |> String.trim
          {p <> usr_include_org,  p <> usr_lib_org}
        end
      end
    _ -> {usr_include_org, usr_lib_org}
  end

will give the "/usr/include" and "/usr/lib" paths.

@cflags_includes in lib/pelemay/generator/builder.ex should be replaced into them.