Skip to content

Commit

Permalink
feature: Added support for FreeBSD, NetBSD, OpenBSD and DragonFly.
Browse files Browse the repository at this point in the history
  • Loading branch information
luau-project committed Nov 15, 2024
1 parent 7ca2733 commit 75d6287
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- "docs/**"

env:
ROCKSPEC_VERSION: 0.0.3
ROCKSPEC_VERSION: 0.0.4
DEV_ROCKSPEC: lua-uuid-dev-1.rockspec

jobs:
Expand Down
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

**lua-uuid** is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).

* On Linux, it uses ```libuuid``` to generate UUIDs;
* On Linux and BSD, it uses ```libuuid``` to generate UUIDs;
* On Windows, it uses the WINAPI ```rpcrt4``` library;
* On MacOS / iOS, it uses the ```CoreFoundation``` framework.
* On macOS / iOS, it uses the ```CoreFoundation``` framework.

## Table of Contents

Expand All @@ -33,19 +33,25 @@

> [!IMPORTANT]
>
> On Linux, ```lua-uuid``` depends on ```libuuid```:
> On Linux and BSD, ```lua-uuid``` depends on ```libuuid```:
>
> * On Debian-based distributions:
> * On Debian-based (e.g: Ubuntu) distributions:
>
> ```bash
> sudo apt install -y uuid-dev
> ```
>
> * On RedHat-based distributions:
> * On RedHat-based (e.g: Fedora) distributions:
>
> ```bash
> sudo dnf install libuuid-devel
> ```
>
> * On BSD-based (e.g: FreeBSD) distributions:
>
> ```bash
> pkg install e2fsprogs-libuuid
> ```
Assuming that [LuaRocks](https://luarocks.org/) is properly installed and configured on your system, execute the following command:

Expand Down Expand Up @@ -165,7 +171,7 @@ print(id3:isnil())

### parse

* *Description*: Generates a new GUID / UUID from a string value
* *Description*: Parses a GUID / UUID from a string value
* *Signature*: ```parse(value)```
* *value* (string): the string to be parsed
* *return*: ```(userdata)```
Expand Down Expand Up @@ -207,8 +213,11 @@ print(id3:isnil())

## Change log

* v0.0.4:
* Added support for BSD (e.g: FreeBSD, NetBSD, OpenBSD and DragonFly);
* Moved ```#include <lua.h>``` and ```LUA_UUID_EXPORT``` macro definition to outside of ```__cplusplus``` declarations on ```lua-uuid.h```.
* v0.0.3:
* Changed to throw issue when ```lua_newuserdata``` returns ```NULL```;
* Changed to throw error when ```lua_newuserdata``` returns ```NULL```;
* Added macro ```LUA_UUID_BUILD_SHARED``` to ```CFLAGS_EXTRA``` on macos;
* Changed ```luajit-master``` to ```luajit``` on CI when testing for ```LuaJIT```;
* Added print statements on [tostring.lua](./samples/tostring.lua) sample;
Expand Down
105 changes: 105 additions & 0 deletions rockspecs/lua-uuid-0.0.4-0.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package = "lua-uuid"
version = "0.0.4-0"

source = {
url = "git://github.com/luau-project/lua-uuid.git",
tag = "v0.0.4"
}

description = {
homepage = "https://github.com/luau-project/lua-uuid",
summary = [[Lightweight, native GUID / UUID library for Lua]],
detailed = [=[
lua-uuid is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
* On Linux and BSD, it uses libuuid to generate UUIDs;
* On Windows, it uses the WINAPI rpcrt4 library;
* On macOS / iOS, it uses the CoreFoundation framework.
Visit the GitHub repository for more information.]=],
license = "MIT"
}

supported_platforms = { "linux", "windows", "cygwin", "macosx", "bsd" }

dependencies = {
"lua >= 5.1"
}

external_dependencies = {
platforms = {
linux = {
["UUID"] = {
header = "uuid/uuid.h"
}
},
bsd = {
["UUID"] = {
header = "uuid/uuid.h"
}
}
}
}

local function build_plat(plat)
if (plat == "linux" or plat == "bsd") then
return {
type = "builtin",
modules = {
["lua-uuid"] = {
sources = { "src/lua-uuid.c" },
libraries = { "uuid" },
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_LIBUUID" },
incdirs = { "src", "$(UUID_INCDIR)" },
libdirs = { "$(UUID_LIBDIR)" }
}
}
}
elseif (plat == "windows" or plat == "cygwin") then
return {
type = "builtin",
modules = {
["lua-uuid"] = {
sources = { "src/lua-uuid.c" },
libraries = { "rpcrt4" },
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_WIN32" },
incdirs = { "src" },
libdirs = { }
}
}
}
elseif (plat == "macosx") then
return {
type = "make",
makefile = "Makefile.macosx",
build_variables = {
CFLAGS = "$(CFLAGS)",
LIBFLAG = "$(LIBFLAG)",
CFLAGS_EXTRA = "-DLUA_UUID_BUILD_SHARED -DLUA_UUID_USE_APPLE",
LIBFLAG_EXTRA = "-framework CoreFoundation",
LUA_INCDIR = "$(LUA_INCDIR)",
LUA_LIBDIR = "$(LUA_INCDIR)/../lib",
OBJ_EXTENSION = "$(OBJ_EXTENSION)",
LIB_EXTENSION = "$(LIB_EXTENSION)"
},
install_variables = {
INSTALL_PREFIX = "$(PREFIX)",
INSTALL_LIBDIR = "$(LIBDIR)",
LUA_VERSION = "$(LUA_VERSION)",
LIB_EXTENSION = "$(LIB_EXTENSION)"
}
}
else
error("Unknown platform", 2)
end
end

build = {
platforms = {
linux = build_plat("linux"),
windows = build_plat("windows"),
cygwin = build_plat("cygwin"),
macosx = build_plat("macosx"),
bsd = build_plat("bsd")
}
}
29 changes: 17 additions & 12 deletions rockspecs/lua-uuid-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ description = {
detailed = [=[
lua-uuid is a lightweight, native library for Lua (5.1 and newer) to deal with Universally Unique Id (UUID).
* On Linux, it uses libuuid to generate UUIDs;
* On Linux and BSD, it uses libuuid to generate UUIDs;
* On Windows, it uses the WINAPI rpcrt4 library;
* On MacOS / iOS, it uses the CoreFoundation framework.
* On macOS / iOS, it uses the CoreFoundation framework.
Visit the GitHub repository for more information.]=],
license = "MIT"
}

supported_platforms = { "linux", "win32", "mingw", "cygwin", "macosx" }
supported_platforms = { "linux", "windows", "cygwin", "macosx", "bsd" }

dependencies = {
"lua >= 5.1"
Expand All @@ -31,12 +31,17 @@ external_dependencies = {
["UUID"] = {
header = "uuid/uuid.h"
}
},
bsd = {
["UUID"] = {
header = "uuid/uuid.h"
}
}
}
}

local function make_plat(plat)
if (plat == "linux") then
local function build_plat(plat)
if (plat == "linux" or plat == "bsd") then
return {
type = "builtin",
modules = {
Expand All @@ -49,7 +54,7 @@ local function make_plat(plat)
}
}
}
elseif (plat == "win32" or plat == "mingw" or plat == "cygwin") then
elseif (plat == "windows" or plat == "cygwin") then
return {
type = "builtin",
modules = {
Expand All @@ -58,7 +63,7 @@ local function make_plat(plat)
libraries = { "rpcrt4" },
defines = { "LUA_UUID_BUILD_SHARED", "LUA_UUID_USE_WIN32" },
incdirs = { "src" },
libdirs = {}
libdirs = { }
}
}
}
Expand Down Expand Up @@ -90,10 +95,10 @@ end

build = {
platforms = {
linux = make_plat("linux"),
win32 = make_plat("win32"),
mingw = make_plat("mingw"),
cygwin = make_plat("cygwin"),
macosx = make_plat("macosx")
linux = build_plat("linux"),
windows = build_plat("windows"),
cygwin = build_plat("cygwin"),
macosx = build_plat("macosx"),
bsd = build_plat("bsd")
}
}
8 changes: 4 additions & 4 deletions src/lua-uuid.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef LUA_UUID_H
#define LUA_UUID_H

#ifdef __cplusplus
extern "C" {
#endif
#include <lua.h>

#ifdef LUA_UUID_BUILD_STATIC
#define LUA_UUID_EXPORT
Expand Down Expand Up @@ -31,7 +29,9 @@ extern "C" {
#endif
#endif

#include <lua.h>
#ifdef __cplusplus
extern "C" {
#endif

LUA_UUID_EXPORT
int luaopen_uuid(lua_State *L);
Expand Down

0 comments on commit 75d6287

Please sign in to comment.