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

WIP: Add support for arm-linux-musleabihf #5862

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/target_machine.cr
Expand Up @@ -18,7 +18,7 @@ module Crystal
# Enable most conservative FPU for hard-float capable targets, unless a
# CPU is defined (it will most certainly enable a better FPU) or
# features contains a floating-point definition.
if cpu.empty? && !features.includes?("fp") && target_triple =~ /-gnueabihf/
if cpu.empty? && !features.includes?("fp") && target_triple =~ /-(gnu|musl)eabihf/
features += "+vfp2"
end
else
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/flags.cr
Expand Up @@ -36,9 +36,12 @@ class Crystal::Program
set.add "x86_64" if set.any?(&.starts_with?("amd64"))
set.add "i686" if set.any? { |flag| %w(i586 i486 i386).includes?(flag) }

set.add "gnu" if set.includes?("gnueabihf")
set.add "musl" if set.includes?("musleabihf")

if set.any?(&.starts_with?("arm"))
set.add "arm"
set.add "armhf" if set.includes?("gnueabihf")
set.add "armhf" if set.includes?("gnueabihf") || set.includes?("musleabihf")
end

if set.includes?("x86_64") || set.includes?("aarch64")
Expand Down
9 changes: 9 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/arpa/inet.cr
@@ -0,0 +1,9 @@
require "../netinet/in"
require "../stdint"

lib LibC
fun htons(x0 : UInt16T) : UInt16T
fun ntohs(x0 : UInt16T) : UInt16T
fun inet_ntop(x0 : Int, x1 : Void*, x2 : Char*, x3 : SocklenT) : Char*
fun inet_pton(x0 : Int, x1 : Char*, x2 : Void*) : Int
end
18 changes: 18 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/dirent.cr
@@ -0,0 +1,18 @@
require "./sys/types"

lib LibC
type DIR = Void

struct Dirent
d_ino : InoT
d_off : OffT
d_reclen : UShort
d_type : Char
d_name : StaticArray(Char, 256)
end

fun closedir(x0 : DIR*) : Int
fun opendir(x0 : Char*) : DIR*
fun readdir(x0 : DIR*) : Dirent*
fun rewinddir(x0 : DIR*) : Void
end
21 changes: 21 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/dlfcn.cr
@@ -0,0 +1,21 @@
lib LibC
RTLD_LAZY = 1
RTLD_NOW = 2
RTLD_GLOBAL = 256
RTLD_LOCAL = 0
RTLD_DEFAULT = Pointer(Void).new(0)
RTLD_NEXT = Pointer(Void).new(-1)

struct DlInfo
dli_fname : Char*
dli_fbase : Void*
dli_sname : Char*
dli_saddr : Void*
end

fun dlclose(x0 : Void*) : Int
fun dlerror : Char*
fun dlopen(x0 : Char*, x1 : Int) : Void*
fun dlsym(x0 : Void*, x1 : Char*) : Void*
fun dladdr(x0 : Void*, x1 : DlInfo*) : Int
end
83 changes: 83 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/errno.cr
@@ -0,0 +1,83 @@
lib LibC
E2BIG = 7
EACCES = 13
EADDRINUSE = 98
EADDRNOTAVAIL = 99
EAFNOSUPPORT = 97
EAGAIN = 11
EALREADY = 114
EBADF = 9
EBADMSG = 74
EBUSY = 16
ECANCELED = 125
ECHILD = 10
ECONNABORTED = 103
ECONNREFUSED = 111
ECONNRESET = 104
EDEADLK = 35
EDESTADDRREQ = 89
EDOM = 33
EDQUOT = 122
EEXIST = 17
EFAULT = 14
EFBIG = 27
EHOSTUNREACH = 113
EIDRM = 43
EILSEQ = 84
EINPROGRESS = 115
EINTR = 4
EINVAL = 22
EIO = 5
EISCONN = 106
EISDIR = 21
ELOOP = 40
EMFILE = 24
EMLINK = 31
EMSGSIZE = 90
EMULTIHOP = 72
ENAMETOOLONG = 36
ENETDOWN = 100
ENETRESET = 102
ENETUNREACH = 101
ENFILE = 23
ENOBUFS = 105
ENODEV = 19
ENOENT = 2
ENOEXEC = 8
ENOLCK = 37
ENOLINK = 67
ENOMEM = 12
ENOMSG = 42
ENOPROTOOPT = 92
ENOSPC = 28
ENOSYS = 38
ENOTCONN = 107
ENOTDIR = 20
ENOTEMPTY = 39
ENOTRECOVERABLE = 131
ENOTSOCK = 88
ENOTSUP = LibC::EOPNOTSUPP
ENOTTY = 25
ENXIO = 6
EOPNOTSUPP = 95
EOVERFLOW = 75
EOWNERDEAD = 130
EPERM = 1
EPIPE = 32
EPROTO = 71
EPROTONOSUPPORT = 93
EPROTOTYPE = 91
ERANGE = 34
EROFS = 30
ESPIPE = 29
ESRCH = 3
ESTALE = 116
ETIMEDOUT = 110
ETXTBSY = 26
EWOULDBLOCK = LibC::EAGAIN
EXDEV = 18
ENODATA = 61
ENOSR = 63
ENOSTR = 60
ETIME = 62
end
32 changes: 32 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/fcntl.cr
@@ -0,0 +1,32 @@
require "./sys/types"
require "./sys/stat"
require "./unistd"

lib LibC
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
FD_CLOEXEC = 1
O_CLOEXEC = 0o2000000
O_CREAT = 0o100
O_NOFOLLOW = 0o100000
O_TRUNC = 0o1000
O_APPEND = 0o2000
O_NONBLOCK = 0o4000
O_SYNC = 0o4010000
O_RDONLY = 0o0
O_RDWR = 0o2
O_WRONLY = 0o1

struct Flock
l_type : Short
l_whence : Short
l_start : OffT
l_len : OffT
l_pid : PidT
end

fun fcntl(x0 : Int, x1 : Int, ...) : Int
fun open(x0 : Char*, x1 : Int, ...) : Int
end
9 changes: 9 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/iconv.cr
@@ -0,0 +1,9 @@
require "./stddef"

lib LibC
type IconvT = Void*

fun iconv(x0 : IconvT, x1 : Char**, x2 : SizeT*, x3 : Char**, x4 : SizeT*) : SizeT
fun iconv_close(x0 : IconvT) : Int
fun iconv_open(x0 : Char*, x1 : Char*) : IconvT
end
39 changes: 39 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/netdb.cr
@@ -0,0 +1,39 @@
require "./netinet/in"
require "./sys/socket"
require "./stdint"

lib LibC
AI_PASSIVE = 0x01
AI_CANONNAME = 0x02
AI_NUMERICHOST = 0x04
AI_NUMERICSERV = 0x400
AI_V4MAPPED = 0x08
AI_ALL = 0x10
AI_ADDRCONFIG = 0x20
EAI_AGAIN = -3
EAI_BADFLAGS = -1
EAI_FAIL = -4
EAI_FAMILY = -6
EAI_MEMORY = -10
EAI_NONAME = -2
EAI_SERVICE = -8
EAI_SOCKTYPE = -7
EAI_SYSTEM = -11
EAI_OVERFLOW = -12

struct Addrinfo
ai_flags : Int
ai_family : Int
ai_socktype : Int
ai_protocol : Int
ai_addrlen : SocklenT
ai_addr : Sockaddr*
ai_canonname : Char*
ai_next : Addrinfo*
end

fun freeaddrinfo(x0 : Addrinfo*) : Void
fun gai_strerror(x0 : Int) : Char*
fun getaddrinfo(x0 : Char*, x1 : Char*, x2 : Addrinfo*, x3 : Addrinfo**) : Int
fun getnameinfo(x0 : Sockaddr*, x1 : SocklenT, x2 : Char*, x3 : SocklenT, x4 : Char*, x5 : SocklenT, x6 : Int) : Int
end
42 changes: 42 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/netinet/in.cr
@@ -0,0 +1,42 @@
require "../sys/socket"
require "../stdint"

lib LibC
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_RAW = 255
IPPROTO_TCP = 6
IPPROTO_UDP = 17

alias InPortT = UInt16T
alias InAddrT = UInt32T

struct InAddr
s_addr : InAddrT
end

union In6AddrIn6Union
__s6_addr : StaticArray(UInt8T, 16)
__s6_addr16 : StaticArray(UInt16T, 8)
__s6_addr32 : StaticArray(UInt32T, 4)
end

struct In6Addr
__in6_union : In6AddrIn6Union
end

struct SockaddrIn
sin_family : SaFamilyT
sin_port : InPortT
sin_addr : InAddr
sin_zero : StaticArray(UInt8T, 8)
end

struct SockaddrIn6
sin6_family : SaFamilyT
sin6_port : InPortT
sin6_flowinfo : UInt32T
sin6_addr : In6Addr
sin6_scope_id : UInt32T
end
end
6 changes: 6 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/netinet/tcp.cr
@@ -0,0 +1,6 @@
lib LibC
TCP_NODELAY = 1
TCP_KEEPIDLE = 4
TCP_KEEPINTVL = 5
TCP_KEEPCNT = 6
end
18 changes: 18 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/pthread.cr
@@ -0,0 +1,18 @@
require "./sys/types"

lib LibC
fun pthread_cond_broadcast(x0 : PthreadCondT*) : Int
fun pthread_cond_destroy(x0 : PthreadCondT*) : Int
fun pthread_cond_init(x0 : PthreadCondT*, x1 : PthreadCondattrT*) : Int
fun pthread_cond_signal(x0 : PthreadCondT*) : Int
fun pthread_cond_wait(x0 : PthreadCondT*, x1 : PthreadMutexT*) : Int
fun pthread_create(x0 : PthreadT*, x1 : PthreadAttrT*, x2 : Void* -> Void*, x3 : Void*) : Int
fun pthread_detach(x0 : PthreadT) : Int
fun pthread_join(x0 : PthreadT, x1 : Void**) : Int
fun pthread_mutex_destroy(x0 : PthreadMutexT*) : Int
fun pthread_mutex_init(x0 : PthreadMutexT*, x1 : PthreadMutexattrT*) : Int
fun pthread_mutex_lock(x0 : PthreadMutexT*) : Int
fun pthread_mutex_trylock(x0 : PthreadMutexT*) : Int
fun pthread_mutex_unlock(x0 : PthreadMutexT*) : Int
fun pthread_self : PthreadT
end
44 changes: 44 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/signal.cr
@@ -0,0 +1,44 @@
require "./sys/types"
require "./time"

lib LibC
SIGHUP = 1
SIGINT = 2
SIGQUIT = 3
SIGILL = 4
SIGTRAP = 5
SIGIOT = LibC::SIGABRT
SIGABRT = 6
SIGFPE = 8
SIGKILL = 9
SIGBUS = 7
SIGSEGV = 11
SIGSYS = 31
SIGPIPE = 13
SIGALRM = 14
SIGTERM = 15
SIGURG = 23
SIGSTOP = 19
SIGTSTP = 20
SIGCONT = 18
SIGCHLD = 17
SIGTTIN = 21
SIGTTOU = 22
SIGIO = 29
SIGXCPU = 24
SIGXFSZ = 25
SIGVTALRM = 26
SIGUSR1 = 10
SIGUSR2 = 12
SIGWINCH = 28
SIGPWR = 30
SIGSTKFLT = 16
SIGUNUSED = LibC::SIGSYS

alias SighandlerT = Int ->
SIG_DFL = SighandlerT.new(Pointer(Void).new(0_u64), Pointer(Void).null)
SIG_IGN = SighandlerT.new(Pointer(Void).new(1_u64), Pointer(Void).null)

fun kill(x0 : PidT, x1 : Int) : Int
fun signal(x0 : Int, x1 : Int -> Void) : Int -> Void
end
3 changes: 3 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/stdarg.cr
@@ -0,0 +1,3 @@
lib LibC
type VaList = Void*
end
3 changes: 3 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/stddef.cr
@@ -0,0 +1,3 @@
lib LibC
alias SizeT = UInt
end
10 changes: 10 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/stdint.cr
@@ -0,0 +1,10 @@
lib LibC
alias Int8T = SChar
alias Int16T = Short
alias Int32T = Int
alias Int64T = LongLong
alias UInt8T = Char
alias UInt16T = UShort
alias UInt32T = UInt
alias UInt64T = ULongLong
end
9 changes: 9 additions & 0 deletions src/lib_c/arm-linux-musleabihf/c/stdio.cr
@@ -0,0 +1,9 @@
require "./sys/types"
require "./stddef"

lib LibC
fun printf(x0 : Char*, ...) : Int
fun dprintf(fd : Int, format : Char*, ...) : Int
fun rename(x0 : Char*, x1 : Char*) : Int
fun snprintf(x0 : Char*, x1 : SizeT, x2 : Char*, ...) : Int
end