Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix building on Mac/Darwin #22

Merged
merged 1 commit into from Aug 31, 2020
Merged

Fix building on Mac/Darwin #22

merged 1 commit into from Aug 31, 2020

Conversation

xvxx
Copy link
Contributor

@xvxx xvxx commented Aug 31, 2020

Hi there, very cool project!

I'm running macOS Catalina and am not able to compile Nelua using just make:

$ make
cc -o nelua-lua \
		-DNDEBUG -DLUA_COMPAT_5_3 -DLUAI_MAXCSTACK=16384 -DLUA_USE_RPMALLOC -DENABLE_GLOBAL_CACHE=0 -DBUILD_DYNAMIC_LINK LUA_USE_POSIX \
		-Ilua \
		-Wall -O2 -fno-plt -fno-stack-protector -flto  \
		-s -Wl,-E  \
		lua/onelua.c rpmalloc/rpmalloc.c lfs.c sys.c hasher.c lpeglabel/*.c  \
		-lm 
clang: error: no such file or directory: 'LUA_USE_POSIX'
make[1]: *** [nelua-lua] Error 1
make: *** [nelua-lua] Error 2

There seem to be a few issues:

  • Need -DLUA_USE_POSIX, not just LUA_USE_POSIX.
  • Need #include <sys/time.h> but _POSIX_TIMERS isn't > 0.
  • Mac's (LLVM's) ld is different from GNU's and doesn't support -s or -E.

This PR just checks for Darwin/Mac and sets the right flags. So far everything seems to work for me, but I'm no expert.

@xvxx xvxx requested a review from edubart as a code owner August 31, 2020 20:18
@edubart edubart merged commit fe0bfb9 into edubart:master Aug 31, 2020
@edubart
Copy link
Owner

edubart commented Aug 31, 2020

Hey many thanks for trying on Mac! The changes looks fine, merged!

I would like to know if all the test suite pass on Mac, to run the you need LuaRocks+Busted installed with Lua 5.4, can be tricky to setup, then you run make test.

@xvxx
Copy link
Contributor Author

xvxx commented Sep 1, 2020

I can get the tests to run if I use my system-installed Lua 5.4 and LuaRocks, but I'm having trouble getting make test to work at all.

Currently stuck on this error:

src/nelua-lua: error loading module 'term.core' from file '/usr/local/lib/lua/5.4/term/core.so':
	dlopen(/usr/local/lib/lua/5.4/term/core.so, 6): Symbol not found: _luaL_checkudata
  Referenced from: /usr/local/lib/lua/5.4/term/core.so
  Expected in: flat namespace
 in /usr/local/lib/lua/5.4/term/core.so

Are you installing LuaRocks using nelua-lua?

FWIW running busted with vanilla 5.4 only has one failing test.

423 successes / 0 failures / 1 error / 0 pending : 26.616514 seconds

Error → spec/08-runner_spec.lua @ 16
Nelua runner should run simple programs
./spec/tools/assert.lua:159: expected success status in run:
C compilation for 'nelua_cache/spec/eval_frsSPfEvbaL' failed:
ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)




stack traceback:
	./nelua/utils/errorer.lua:14: in function 'nelua.utils.errorer.assertf'
	./spec/tools/assert.lua:159: in function 'luassert.assert.run'
	spec/08-runner_spec.lua:24: in function <spec/08-runner_spec.lua:16>
    

@xvxx xvxx mentioned this pull request Sep 1, 2020
@edubart
Copy link
Owner

edubart commented Sep 1, 2020

Running with the bundled nelua lua interpreter failed mostly because it was unable to find the LuaRocks libraries I think (would requires fixing the LUA_PATH system's environment variable).

But running with vanilla Lua is enough! Thanks for running the tests!
Seems like things mostly worked fine there, I will try fix that test on MacOS later (seems like to be the ld from MacOS also does not support --as-needed flag)

@xvxx
Copy link
Contributor Author

xvxx commented Sep 1, 2020

Running with the bundled nelua lua interpreter failed mostly because it was unable to find the LuaRocks libraries I think (would requires fixing the LUA_PATH system's environment variable).

I did run into that issue at first, but I'm able to get past that by setting LUA_PATH and LUA_CPATH (which I omitted in my comment above):

$ make test
make[1]: Nothing to be done for `default'.
busted --lua=src/nelua-lua
src/nelua-lua: /usr/local/lib/luarocks/rocks-5.4/busted/2.0.0-1/bin/busted:3: module 'busted.runner' not found:
	no field package.preload['busted.runner']
	no file '/usr/share/lua/5.4/busted/runner.lua'
	no file '/usr/share/lua/5.4/busted/runner/init.lua'
	no file '/usr/lib/lua/5.4/busted/runner.lua'
	no file '/usr/lib/lua/5.4/busted/runner/init.lua'
	no file './busted/runner.lua'
	no file './busted/runner/init.lua'
	no file '/usr/lib/lua/5.4/busted/runner.so'
	no file '/usr/lib/lua/5.4/loadall.so'
	no file './busted/runner.so'
	no file '/usr/lib/lua/5.4/busted.so'
	no file '/usr/lib/lua/5.4/loadall.so'
	no file './busted.so'
stack traceback:
	[C]: in function 'require'
	/usr/local/lib/luarocks/rocks-5.4/busted/2.0.0-1/bin/busted:3: in main chunk
	[C]: in ?
make: *** [test] Error 1
$ make test LUA_CPATH="/usr/local/lib/lua/5.4/?.so;/usr/lib/lua/5.4/?.so;/usr/lib/lua/5.4/loadall.so;./?.so" LUA_PATH="/usr/local/share/lua/5.4/?.lua;/usr/local/share/lua/5.4/?/init.lua;/usr/share/lua/5.4/?.lua;/usr/share/lua/5.4/?/init.lua;/usr/lib/lua/5.4/?.lua;/usr/lib/lua/5.4/?/init.lua;./?.lua;./?/init.lua"
make[1]: Nothing to be done for `default'.
busted --lua=src/nelua-lua
src/nelua-lua: error loading module 'term.core' from file '/usr/local/lib/lua/5.4/term/core.so':
	dlopen(/usr/local/lib/lua/5.4/term/core.so, 6): Symbol not found: _luaL_checkudata
  Referenced from: /usr/local/lib/lua/5.4/term/core.so
  Expected in: flat namespace
 in /usr/local/lib/lua/5.4/term/core.so
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	/usr/local/share/lua/5.4/term/init.lua:21: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.4/busted/runner.lua:5: in main chunk
	[C]: in function 'require'
	/usr/local/lib/luarocks/rocks-5.4/busted/2.0.0-1/bin/busted:3: in main chunk
	[C]: in ?
make: *** [test] Error 1

The luaL_checkudata function is part of Lua:

http://www.lua.org/source/5.4/lauxlib.c.html#luaL_checkudata

So I'm thinking this might mean that compiling on macOS isn't totally fixed yet? Seems like I might not have the right linker flags set.

@edubart
Copy link
Owner

edubart commented Sep 1, 2020

This is fine, just the test suite is failing to run there due to busted dependencies, users don't need install busted or run the test suite to use Nelua, this is more for developers of the language (me). What is important for users on MacOS is to run files in the examples and tests folder, and from what I understood worked for you.

make test LUA_CPATH=...

Actually you should have exported the variable, like:

export LUA_CPATH=...
export LUA_PATH=...
make test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants