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

Compiling on windows (through luarocks) fails, it thinks my system is POSIX #63

Closed
Frityet opened this issue Feb 19, 2024 · 10 comments · Fixed by #64
Closed

Compiling on windows (through luarocks) fails, it thinks my system is POSIX #63

Frityet opened this issue Feb 19, 2024 · 10 comments · Fixed by #64

Comments

@Frityet
Copy link

Frityet commented Feb 19, 2024

PS C:\Users\Frit\Documents> luarocks install tabular
Installing https://luarocks.org/tabular-0.4-1.src.rock
Missing dependencies for tabular 0.4-1:
   compat53 (not installed)
   ansicolors ~> 1.0 (not installed)

tabular 0.4-1 depends on lua >= 5.1 (5.4-1 provided by VM)
tabular 0.4-1 depends on compat53 (not installed)
Installing https://luarocks.org/compat53-0.12-1.src.rock

compat53 0.12-1 depends on lua >= 5.1, < 5.5 (5.4-1 provided by VM)
"C:\Program Files\LLVM\bin\gcc.exe" -O2 -c -o lutf8lib.o -IC:\Program Files\Lua\5.4\include lutf8lib.c
"C:\Program Files\LLVM\bin\gcc.exe"  -shared -o compat53/utf8.dll lutf8lib.o C:\Program Files\Lua\5.4\lib/lua54.dll -lucrt
"C:\Program Files\LLVM\bin\gcc.exe" -O2 -c -o lstrlib.o -IC:\Program Files\Lua\5.4\include lstrlib.c
"C:\Program Files\LLVM\bin\gcc.exe"  -shared -o compat53/string.dll lstrlib.o C:\Program Files\Lua\5.4\lib/lua54.dll -lucrt
"C:\Program Files\LLVM\bin\gcc.exe" -O2 -c -o liolib.o -IC:\Program Files\Lua\5.4\include liolib.c
liolib.c:408:13: error: call to undeclared function 'getc_unlocked'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  408 |     rn->c = l_getc(rn->f);  /* read next one */
      |             ^
liolib.c:86:20: note: expanded from macro 'l_getc'
   86 | #define l_getc(f)               getc_unlocked(f)
      |                                 ^
liolib.c:448:3: error: call to undeclared function 'flockfile'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  448 |   l_lockfile(rn.f);
      |   ^
liolib.c:87:24: note: expanded from macro 'l_lockfile'
   87 | #define l_lockfile(f)           flockfile(f)
      |                                 ^
liolib.c:448:3: note: did you mean '_lock_file'?
liolib.c:87:24: note: expanded from macro 'l_lockfile'
   87 | #define l_lockfile(f)           flockfile(f)
      |                                 ^
C:/Program Files/LLVM/include/stdio.h:1533:24: note: '_lock_file' declared here
 1533 |   _CRTIMP void __cdecl _lock_file(FILE *_File);
      |                        ^
liolib.c:449:15: error: call to undeclared function 'getc_unlocked'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  449 |   do { rn.c = l_getc(rn.f); } while (isspace(rn.c));  /* skip spaces */
      |               ^
liolib.c:86:20: note: expanded from macro 'l_getc'
   86 | #define l_getc(f)               getc_unlocked(f)
      |                                 ^
liolib.c:463:3: error: call to undeclared function 'funlockfile'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  463 |   l_unlockfile(rn.f);
      |   ^
liolib.c:88:26: note: expanded from macro 'l_unlockfile'
   88 | #define l_unlockfile(f)         funlockfile(f)
      |                                 ^
liolib.c:489:5: error: call to undeclared function 'flockfile'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  489 |     l_lockfile(f);  /* no memory errors can happen inside the lock */
      |     ^
liolib.c:87:24: note: expanded from macro 'l_lockfile'
   87 | #define l_lockfile(f)           flockfile(f)
      |                                 ^
liolib.c:490:40: error: call to undeclared function 'getc_unlocked'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  490 |     while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
      |                                        ^
liolib.c:86:20: note: expanded from macro 'l_getc'
   86 | #define l_getc(f)               getc_unlocked(f)
      |                                 ^
liolib.c:492:5: error: call to undeclared function 'funlockfile'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  492 |     l_unlockfile(f);
      |     ^
liolib.c:88:26: note: expanded from macro 'l_unlockfile'
   88 | #define l_unlockfile(f)         funlockfile(f)
      |                                 ^
7 errors generated.

Error: Failed installing dependency: https://luarocks.org/compat53-0.12-1.src.rock - Build error: Failed compiling object liolib.o
@hishamhm
Copy link
Member

hishamhm commented Feb 19, 2024

This is odd because it should be getting those defines from your lua.h settings. Does this rockspec work?

You can save this file as compat53-0.12-1.rockspec and run luarocks build compat53-0.12-1.rockspec.

package = "compat53"
version = "0.12-1"
source = {
   url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.12.zip",
   dir = "lua-compat-5.3-0.12",
}
description = {
   summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1",
   detailed = [[
      This is a small module that aims to make it easier to write Lua
      code in a Lua-5.3-style that runs on Lua 5.1+.
      It does *not* make Lua 5.2 (or even 5.1) entirely compatible
      with Lua 5.3, but it brings the API closer to that of Lua 5.3.
   ]],
   homepage = "https://github.com/lunarmodules/lua-compat-5.3",
   license = "MIT"
}
dependencies = {
   "lua >= 5.1, < 5.5",
   --"struct" -- make Roberto's struct module optional
}
build = {
   type = "builtin",
   modules = {
      ["compat53.init"] = "compat53/init.lua",
      ["compat53.module"] = "compat53/module.lua",
      ["compat53.utf8"] = "lutf8lib.c",
      ["compat53.table"] = "ltablib.c",
      ["compat53.string"] = "lstrlib.c",
      ["compat53.io"] = {
         sources = { "liolib.c" },
      }
   },
   platforms = {
      windows = {
         modules = {
            ["compat53.io"] = {
               defines = { "LUA_USE_WINDOWS" },
            }
         }
      }
   }
}

@hishamhm
Copy link
Member

Unfortunately I don't have a Windows system to test this on, so any help debugging this is much appreciated!

@Frityet
Copy link
Author

Frityet commented Feb 20, 2024

This is odd because it should be getting those defines from your lua.h settings. Does this rockspec work?

You can save this file as compat53-0.12-1.rockspec and run luarocks build compat53-0.12-1.rockspec.

package = "compat53"

version = "0.12-1"

source = {

   url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.12.zip",

   dir = "lua-compat-5.3-0.12",

}

description = {

   summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1",

   detailed = [[

      This is a small module that aims to make it easier to write Lua

      code in a Lua-5.3-style that runs on Lua 5.1+.

      It does *not* make Lua 5.2 (or even 5.1) entirely compatible

      with Lua 5.3, but it brings the API closer to that of Lua 5.3.

   ]],

   homepage = "https://github.com/lunarmodules/lua-compat-5.3",

   license = "MIT"

}

dependencies = {

   "lua >= 5.1, < 5.5",

   --"struct" -- make Roberto's struct module optional

}

build = {

   type = "builtin",

   modules = {

      ["compat53.init"] = "compat53/init.lua",

      ["compat53.module"] = "compat53/module.lua",

      ["compat53.utf8"] = "lutf8lib.c",

      ["compat53.table"] = "ltablib.c",

      ["compat53.string"] = "lstrlib.c",

      ["compat53.io"] = {

         sources = { "liolib.c" },

      }

   },

   platforms = {

      windows = {

         modules = {

            ["compat53.io"] = {

               defines = { "LUA_USE_WINDOWS" },

            }

         }

      }

   }

}


I'll try this too, I am using the latest (like latest commit) of luarocks because it seems to be the only one that works well on windows

@hishamhm
Copy link
Member

the latest (like latest commit) of luarocks because it seems to be the only one that works well on windows

That is encouraging to hear :) I am planning to cut a new LuaRocks release by the end of the week.

@Frityet
Copy link
Author

Frityet commented Feb 23, 2024

This is odd because it should be getting those defines from your lua.h settings. Does this rockspec work?

You can save this file as compat53-0.12-1.rockspec and run luarocks build compat53-0.12-1.rockspec.

package = "compat53"
version = "0.12-1"
source = {
   url = "https://github.com/lunarmodules/lua-compat-5.3/archive/v0.12.zip",
   dir = "lua-compat-5.3-0.12",
}
description = {
   summary = "Compatibility module providing Lua-5.3-style APIs for Lua 5.2 and 5.1",
   detailed = [[
      This is a small module that aims to make it easier to write Lua
      code in a Lua-5.3-style that runs on Lua 5.1+.
      It does *not* make Lua 5.2 (or even 5.1) entirely compatible
      with Lua 5.3, but it brings the API closer to that of Lua 5.3.
   ]],
   homepage = "https://github.com/lunarmodules/lua-compat-5.3",
   license = "MIT"
}
dependencies = {
   "lua >= 5.1, < 5.5",
   --"struct" -- make Roberto's struct module optional
}
build = {
   type = "builtin",
   modules = {
      ["compat53.init"] = "compat53/init.lua",
      ["compat53.module"] = "compat53/module.lua",
      ["compat53.utf8"] = "lutf8lib.c",
      ["compat53.table"] = "ltablib.c",
      ["compat53.string"] = "lstrlib.c",
      ["compat53.io"] = {
         sources = { "liolib.c" },
      }
   },
   platforms = {
      windows = {
         modules = {
            ["compat53.io"] = {
               defines = { "LUA_USE_WINDOWS" },
            }
         }
      }
   }
}

Just got a chance to test it (had to create a new windows VM) same error, but I realise its using my luaconf.h I copied to my include dir. Should I have a luaconf.h there? I just copied it directly from the lua source tree when I built lua

"C:\Program Files\LLVM\bin\gcc.exe" -O2 -c -o liolib.o -IC:\Program Files\Lua\5.4\include liolib.c -DLUA_USE_WINDOWS
In file included from liolib.c:10:
In file included from ./lprefix.h:46:
In file included from ./c-api/compat-5.3.h:10:
In file included from C:\Program Files\Lua\5.4\include/lua.h:16:
C:\Program Files\Lua\5.4\include/luaconf.h:51:9: warning: 'LUA_USE_WINDOWS' macro redefined [-Wmacro-redefined]
   51 | #define LUA_USE_WINDOWS  /* enable goodies for regular Windows */
      |         ^
<command line>:1:9: note: previous definition is here
    1 | #define LUA_USE_WINDOWS 1
      |         ^
liolib.c:408:13: error: call to undeclared function 'getc_unlocked'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  408 |     rn->c = l_getc(rn->f);  /* read next one */
      |             ^

@hishamhm
Copy link
Member

hishamhm commented Feb 23, 2024

Should I have a luaconf.h there?

Yes, Lua installations include luaconf.h (e.g. the Ubuntu package installs /usr/include/lua5.4/luaconf.h).

C:\Program Files\Lua\5.4\include/luaconf.h:51:9: warning: 'LUA_USE_WINDOWS' macro redefined

Ok, so that means that the Lua headers do attempt to set LUA_USE_WINDOWS on your system. This means that the rockspec I sent you is not the right way to go, as it was trying to force that explicitly in that rockspec.

The reason why I wanted to try that rockspec is because this error...

"C:\Program Files\LLVM\bin\gcc.exe" -O2 -c -o liolib.o -IC:\Program Files\Lua\5.4\include liolib.c
liolib.c:408:13: error: call to undeclared function 'getc_unlocked'; ISO C99 and later do not support implicit function
      declarations [-Wimplicit-function-declaration]
  408 |     rn->c = l_getc(rn->f);  /* read next one */
      |             ^
liolib.c:86:20: note: expanded from macro 'l_getc'
   86 | #define l_getc(f)               getc_unlocked(f)

...is happening due to that line 86:

#define l_getc(f) getc_unlocked(f)

...which is inside a LUA_USE_POSIX block!

Perhaps there's some difference in configuration between the system in your original message and the Windows VM where you tried this rockspec? Does the original rockspec fail the same way as the original message in the Windows VM?

I don't see a way how LUA_USE_WINDOWS and LUA_USE_POSIX can be active at the same time...

Thank you for the testing! Let's keep digging this!

@hishamhm
Copy link
Member

Oh wait, looks like compat-5.3 really is doing something wrong here:

lua-compat-5.3/lprefix.h

Lines 197 to 204 in 737264a

/* choose which popen implementation to pick */
# if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \
(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || \
defined(__APPLE__)
# define LUA_USE_POSIX 1
# elif (defined(_MSC_VER))
# define LUA_USE_WINDOWS 0
# endif

I made this PR to try to fix the issue: #64

Could you test it? You should be able to do that by fetching that branch and then running luarocks make rockspecs/compat53-scm-0.rockspec. Thank you!!

@Frityet
Copy link
Author

Frityet commented Feb 23, 2024

Could you test it? You should be able to do that by fetching that branch and then running luarocks make rockspecs/compat53-scm-0.rockspec. Thank you!!

Will do! Give me a moment

@Frityet
Copy link
Author

Frityet commented Feb 23, 2024

Fixed in #64

@Frityet Frityet closed this as completed Feb 23, 2024
@hishamhm
Copy link
Member

Compat-5.3 0.13 is released!!

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

Successfully merging a pull request may close this issue.

2 participants