Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
osQnx, osAtari, osAix,
osHaiku, osVxWorks, osSolaris, osNetbsd,
osFreebsd, osOpenbsd, osDragonfly, osMacosx, osIos,
osAndroid, osNintendoSwitch, osFreeRTOS, osCrossos, osZephyr}
osAndroid, osNintendoSwitch, osFreeRTOS, osCrossos, osZephyr, osNuttX}
of "linux":
result = conf.target.targetOS in {osLinux, osAndroid}
of "bsd":
Expand All @@ -643,6 +643,8 @@ proc isDefined*(conf: ConfigRef; symbol: string): bool =
result = conf.target.targetOS == osFreeRTOS
of "zephyr":
result = conf.target.targetOS == osZephyr
of "nuttx":
result = conf.target.targetOS == osNuttX
of "littleendian": result = CPU[conf.target.targetCPU].endian == littleEndian
of "bigendian": result = CPU[conf.target.targetCPU].endian == bigEndian
of "cpu8": result = CPU[conf.target.targetCPU].bit == 8
Expand Down
7 changes: 6 additions & 1 deletion compiler/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type
osNone, osDos, osWindows, osOs2, osLinux, osMorphos, osSkyos, osSolaris,
osIrix, osNetbsd, osFreebsd, osOpenbsd, osDragonfly, osCrossos, osAix, osPalmos, osQnx,
osAmiga, osAtari, osNetware, osMacos, osMacosx, osIos, osHaiku, osAndroid, osVxWorks
osGenode, osJS, osNimVM, osStandalone, osNintendoSwitch, osFreeRTOS, osZephyr, osAny
osGenode, osJS, osNimVM, osStandalone, osNintendoSwitch, osFreeRTOS, osZephyr,
osNuttX, osAny

type
TInfoOSProp* = enum
Expand Down Expand Up @@ -193,6 +194,10 @@ const
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
scriptExt: ".sh", curDir: ".", exeExt: "", extSep: ".",
props: {ospPosix}),
(name: "NuttX", parDir: "..", dllFrmt: "lib$1.so", altDirSep: "/",
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
scriptExt: ".sh", curDir: ".", exeExt: "", extSep: ".",
props: {ospPosix}),
(name: "Any", parDir: "..", dllFrmt: "lib$1.so", altDirSep: "/",
objExt: ".o", newLine: "\x0A", pathSep: ":", dirSep: "/",
scriptExt: ".sh", curDir: ".", exeExt: "", extSep: ".",
Expand Down
5 changes: 4 additions & 1 deletion lib/posix/posix_other.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
when defined(nimHasStyleChecks):
{.push styleChecks: off.}

when defined(freertos) or defined(zephyr):
when defined(freertos) or defined(zephyr) or defined(nuttx):
const
hasSpawnH = false # should exist for every Posix system nowadays
hasAioH = false
Expand Down Expand Up @@ -640,6 +640,9 @@ when defined(linux) or defined(nimdoc):
## or UDP packets. (Requires Linux kernel > 3.9)
else:
const SO_REUSEPORT* = cint(15)
elif defined(nuttx):
# Not supported, use SO_REUSEADDR to avoid compilation errors.
var SO_REUSEPORT* {.importc: "SO_REUSEADDR", header: "<sys/socket.h>".}: cint
else:
var SO_REUSEPORT* {.importc, header: "<sys/socket.h>".}: cint

Expand Down
13 changes: 12 additions & 1 deletion lib/posix/posix_other_consts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ var EXDEV* {.importc: "EXDEV", header: "<errno.h>".}: cint

# <fcntl.h>
var F_DUPFD* {.importc: "F_DUPFD", header: "<fcntl.h>".}: cint
var F_DUPFD_CLOEXEC* {.importc: "F_DUPFD", header: "<fcntl.h>".}: cint
when defined(nuttx):
var F_DUPFD_CLOEXEC* {.importc: "F_DUPFD_CLOEXEC", header: "<fcntl.h>".}: cint
else:
var F_DUPFD_CLOEXEC* {.importc: "F_DUPFD", header: "<fcntl.h>".}: cint
var F_GETFD* {.importc: "F_GETFD", header: "<fcntl.h>".}: cint
var F_SETFD* {.importc: "F_SETFD", header: "<fcntl.h>".}: cint
var F_GETFL* {.importc: "F_GETFL", header: "<fcntl.h>".}: cint
Expand Down Expand Up @@ -127,6 +130,11 @@ var O_RDONLY* {.importc: "O_RDONLY", header: "<fcntl.h>".}: cint
var O_RDWR* {.importc: "O_RDWR", header: "<fcntl.h>".}: cint
var O_WRONLY* {.importc: "O_WRONLY", header: "<fcntl.h>".}: cint
var O_CLOEXEC* {.importc: "O_CLOEXEC", header: "<fcntl.h>".}: cint
when defined(nuttx):
var O_DIRECT* {.importc: "O_DIRECT", header: "<fcntl.h>".}: cint
var O_PATH* {.importc: "O_PATH", header: "<fcntl.h>".}: cint
var O_NOATIME* {.importc: "O_NOATIME", header: "<fcntl.h>".}: cint
var O_TMPFILE* {.importc: "O_TMPFILE", header: "<fcntl.h>".}: cint
var POSIX_FADV_NORMAL* {.importc: "POSIX_FADV_NORMAL", header: "<fcntl.h>".}: cint
var POSIX_FADV_SEQUENTIAL* {.importc: "POSIX_FADV_SEQUENTIAL", header: "<fcntl.h>".}: cint
var POSIX_FADV_RANDOM* {.importc: "POSIX_FADV_RANDOM", header: "<fcntl.h>".}: cint
Expand Down Expand Up @@ -465,6 +473,9 @@ var FD_SETSIZE* {.importc: "FD_SETSIZE", header: "<sys/select.h>".}: cint
when defined(zephyr):
# Zephyr specific hardcoded value
var FD_MAX* {.importc: "CONFIG_POSIX_MAX_FDS ", header: "<sys/select.h>".}: cint
elif defined(nuttx):
# NuttX specific user configuration value
var NACTIVESOCKETS* {.importc: "CONFIG_NET_NACTIVESOCKETS", header: "<nuttx/config.h>".}: cint

# <sys/socket.h>
var MSG_CTRUNC* {.importc: "MSG_CTRUNC", header: "<sys/socket.h>".}: cint
Expand Down
5 changes: 4 additions & 1 deletion lib/pure/asyncdispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2024,7 +2024,7 @@ when defined(posix):
import posix

when defined(linux) or defined(windows) or defined(macosx) or defined(bsd) or
defined(solaris) or defined(zephyr) or defined(freertos):
defined(solaris) or defined(zephyr) or defined(freertos) or defined(nuttx):
proc maxDescriptors*(): int {.raises: OSError.} =
## Returns the maximum number of active file descriptors for the current
## process. This involves a system call. For now `maxDescriptors` is
Expand All @@ -2033,6 +2033,9 @@ when defined(linux) or defined(windows) or defined(macosx) or defined(bsd) or
result = 16_700_000
elif defined(zephyr) or defined(freertos):
result = FD_MAX
elif defined(nuttx):
# The maximum number of concurrently active UDP and TCP ports.
result = NACTIVESOCKETS
else:
var fdLim: RLimit
if getrlimit(RLIMIT_NOFILE, fdLim) < 0:
Expand Down
5 changes: 3 additions & 2 deletions lib/pure/asynchttpserver.nim
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,9 @@ proc listen*(server: AsyncHttpServer; port: Port; address = ""; domain = AF_INET
server.socket = newAsyncSocket(domain)
if server.reuseAddr:
server.socket.setSockOpt(OptReuseAddr, true)
if server.reusePort:
server.socket.setSockOpt(OptReusePort, true)
when not defined(nuttx):
if server.reusePort:
server.socket.setSockOpt(OptReusePort, true)
server.socket.bindAddr(port, address)
server.socket.listen()

Expand Down
3 changes: 2 additions & 1 deletion lib/pure/asyncnet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export SOBool
# TODO: Remove duplication introduced by PR #4683.

const defineSsl = defined(ssl) or defined(nimdoc)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr) or
defined(nuttx)

when defineSsl:
import openssl
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/ioselects/ioselectors_select.nim
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ proc selectInto*[T](s: Selector[T], timeout: int,
verifySelectParams(timeout)

if timeout != -1:
when defined(genode) or defined(freertos) or defined(zephyr):
when defined(genode) or defined(freertos) or defined(zephyr) or defined(nuttx):
tv.tv_sec = Time(timeout div 1_000)
else:
tv.tv_sec = timeout.int32 div 1_000
Expand Down
7 changes: 4 additions & 3 deletions lib/pure/nativesockets.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ when hostOS == "solaris":
{.passl: "-lsocket -lnsl".}

const useWinVersion = defined(windows) or defined(nimdoc)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr) or
defined(nuttx)

when useWinVersion:
import winlean
Expand Down Expand Up @@ -304,7 +305,7 @@ proc getAddrInfo*(address: string, port: Port, domain: Domain = AF_INET,
let socketPort = if sockType == SOCK_RAW: "" else: $port
var gaiResult = getaddrinfo(address, socketPort.cstring, addr(hints), result)
if gaiResult != 0'i32:
when useWinVersion or defined(freertos):
when useWinVersion or defined(freertos) or defined(nuttx):
raiseOSError(osLastError())
else:
raiseOSError(osLastError(), $gai_strerror(gaiResult))
Expand Down Expand Up @@ -351,7 +352,7 @@ proc getSockDomain*(socket: SocketHandle): Domain =
else:
raise newException(IOError, "Unknown socket family in getSockDomain")

when not useNimNetLite:
when not useNimNetLite:
proc getServByName*(name, proto: string): Servent {.tags: [ReadIOEffect].} =
## Searches the database from the beginning and finds the first entry for
## which the service name specified by `name` matches the s_name member
Expand Down
3 changes: 2 additions & 1 deletion lib/pure/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export nativesockets.Port, nativesockets.`$`, nativesockets.`==`
export Domain, SockType, Protocol

const useWinVersion = defined(windows) or defined(nimdoc)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr)
const useNimNetLite = defined(nimNetLite) or defined(freertos) or defined(zephyr) or
defined(nuttx)
const defineSsl = defined(ssl) or defined(nimdoc)

when useWinVersion:
Expand Down
9 changes: 7 additions & 2 deletions lib/pure/selectors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const hasThreadSupport = compileOption("threads") and defined(threadsafe)

const ioselSupportedPlatform* = defined(macosx) or defined(freebsd) or
defined(netbsd) or defined(openbsd) or
defined(dragonfly) or
defined(dragonfly) or defined(nuttx) or
(defined(linux) and not defined(android) and not defined(emscripten))
## This constant is used to determine whether the destination platform is
## fully supported by `ioselectors` module.
Expand Down Expand Up @@ -328,7 +328,7 @@ else:
doAssert(timeout >= -1, "Cannot select with a negative value, got: " & $timeout)

when defined(linux) or defined(windows) or defined(macosx) or defined(bsd) or
defined(solaris) or defined(zephyr) or defined(freertos):
defined(solaris) or defined(zephyr) or defined(freertos) or defined(nuttx):
template maxDescriptors*(): int =
## Returns the maximum number of active file descriptors for the current
## process. This involves a system call. For now `maxDescriptors` is
Expand All @@ -337,6 +337,9 @@ else:
16_700_000
elif defined(zephyr) or defined(freertos):
FD_MAX
elif defined(nuttx):
# The maximum number of concurrently active UDP and TCP ports.
NACTIVESOCKETS
else:
var fdLim: RLimit
var res = int(getrlimit(RLIMIT_NOFILE, fdLim))
Expand All @@ -360,5 +363,7 @@ else:
include ioselects/ioselectors_select
elif defined(zephyr):
include ioselects/ioselectors_poll
elif defined(nuttx):
include ioselects/ioselectors_epoll
else:
include ioselects/ioselectors_poll
3 changes: 2 additions & 1 deletion lib/std/typedthreads.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ when defined(genode):
import genode/env


when hasAllocStack or defined(zephyr) or defined(freertos) or defined(cpu16) or defined(cpu8):
when hasAllocStack or defined(zephyr) or defined(freertos) or defined(nuttx) or
defined(cpu16) or defined(cpu8):
const
nimThreadStackSize {.intdefine.} = 8192
nimThreadStackGuard {.intdefine.} = 128
Expand Down
1 change: 1 addition & 0 deletions lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2688,6 +2688,7 @@ when notJSnotNims:
not defined(nintendoswitch) and
not defined(freertos) and
not defined(zephyr) and
not defined(nuttx) and
hostOS != "any"

proc raiseEIO(msg: string) {.noinline, noreturn.} =
Expand Down
2 changes: 1 addition & 1 deletion lib/system/dyncalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ elif defined(genode):
proc nimGetProcAddr(lib: LibHandle, name: cstring): ProcAddr =
raiseAssert("nimGetProcAddr not implemented")

elif defined(nintendoswitch) or defined(freertos) or defined(zephyr):
elif defined(nintendoswitch) or defined(freertos) or defined(zephyr) or defined(nuttx):
proc nimUnloadLibrary(lib: LibHandle) =
cstderr.rawWrite("nimUnLoadLibrary not implemented")
cstderr.rawWrite("\n")
Expand Down