-
-
Notifications
You must be signed in to change notification settings - Fork 411
[RFC] Initial support for building druntime with musl libc #1997
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,6 +298,25 @@ else version( Solaris ) | |
|
|
||
| alias int fexcept_t; | ||
| } | ||
| else version( CRuntime_Musl ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Historically, druntime was written in a different code-style, but for all new code we try to follow https://dlang.org/dstyle.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Druntime uses both styles, I'm guessing he just copy-pasted this style from above. No need to nitpick this, can always change it later. |
||
| { | ||
| struct fenv_t { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not correct, since else version (CRuntime_Musl)
{
// http://git.musl-libc.org/cgit/musl/tree/arch/i386/bits/fenv.h
version (X86)
{
struct fenv_t
{
ushort __control_word;
ushort __unused1;
ushort __status_word;
ushort __unused2;
ushort __tags;
ushort __unused3;
uint __eip;
ushort __cs_selector;
ushort __opcode;
uint __data_offset;
ushort __data_selector;
ushort __unused5;
}
alias fexcept_t = ushort;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/x86_64/bits/fenv.h
else version (X86_64)
{
struct fenv_t
{
ushort __control_word;
ushort __unused1;
ushort __status_word;
ushort __unused2;
ushort __tags;
ushort __unused3;
uint __eip;
ushort __cs_selector;
ushort __opcode;
uint __data_offset;
ushort __data_selector;
ushort __unused5;
uint __mxcsr;
}
alias fexcept_t = ushort;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/mipsn32/bits/fenv.h
else version (MIPS32)
{
struct fenv_t
{
uint __cw;
}
alias fexcept_t = ushort;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/mips64/bits/fenv.h
else version (MIPS64)
{
struct fenv_t
{
uint __cw;
}
alias fexcept_t = ushort;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/aarch64/bits/fenv.h
else version (AArch64)
{
struct fenv_t
{
uint __fpcr;
uint __fpsr;
}
alias fexcept_t = uint;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/arm/bits/fenv.h
else version (ARM)
{
struct fenv_t
{
// FIXME: musl defines this as `unsigned long` - check if
// this actually is 32-bits in size
uint __cw;
}
// FIXME: musl defines this as `unsigned long` - check if
// this actually is 32-bits in size
alias fexcept_t = uint;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/powerpc64/bits/fenv.h
else version (PPC64)
{
alias fenv_t = double;
alias fexcept_t = uint;
}
// http://git.musl-libc.org/cgit/musl/tree/arch/s390x/bits/fenv.h
else version (SystemZ)
{
// Note: different from the glibc implementation:
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/s390/fpu/bits/fenv.h
alias fenv_t = uint;
alias fexcept_t = uint;
}
else
{
static assert(0, "Unimplemented architecture support for musl libc");
}
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While Petar is right that architecture-dependent code should be versioned like this, you don't have to add any arch that you have not tried, so just adding the |
||
| ushort __control_word; | ||
| ushort __unused1; | ||
| ushort __status_word; | ||
| ushort __unused2; | ||
| ushort __tags; | ||
| ushort __unused3; | ||
| uint __eip; | ||
| ushort __cs_selector; | ||
| ushort __opcode; | ||
| uint __data_offset; | ||
| ushort __data_selector; | ||
| ushort __unused5; | ||
| uint __mxcsr; | ||
| } | ||
| alias ushort fexcept_t; | ||
| } | ||
| else | ||
| { | ||
| static assert( false, "Unsupported platform" ); | ||
|
|
@@ -623,6 +642,9 @@ else version( Solaris ) | |
| /// | ||
| enum FE_DFL_ENV = &__fenv_def_env; | ||
| } | ||
| else version( CRuntime_Musl ) | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // http://git.musl-libc.org/cgit/musl/tree/arch/generic/bits/fenv.h#n10
// (implemented the same way for all architectures)
enum FE_DFL_ENV = cast(fenv_t*)(-1); |
||
| } | ||
| else | ||
| { | ||
| static assert( false, "Unsupported platform" ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,9 @@ else version(Solaris) | |
| /// | ||
| enum LC_ALL = 6; | ||
| } | ||
| else version(CRuntime_Musl) | ||
| { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else version (CRuntime_Musl)
{
// http://git.musl-libc.org/cgit/musl/tree/include/locale.h
///
enum LC_CTYPE = 0;
///
enum LC_NUMERIC = 1;
///
enum LC_TIME = 2;
///
enum LC_COLLATE = 3;
///
enum LC_MONETARY = 4;
///
enum LC_MESSAGES = 5;
///
enum LC_ALL = 6;
} |
||
| } | ||
| else | ||
| { | ||
| static assert(false, "Unsupported platform"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,24 @@ else version( CRuntime_Glibc ) | |
| L_tmpnam = 20 | ||
| } | ||
| } | ||
| else version( CRuntime_Musl ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else version (CRuntime_Musl) |
||
| { | ||
| enum | ||
| { | ||
| /// | ||
| BUFSIZ = 8192, | ||
| /// | ||
| EOF = -1, | ||
| /// | ||
| FOPEN_MAX = 16, | ||
| /// | ||
| FILENAME_MAX = 4095, | ||
| /// | ||
| TMP_MAX = 238328, | ||
| /// | ||
| L_tmpnam = 20 | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure where you got those numbers from, but in http://git.musl-libc.org/cgit/musl/tree/include/stdio.h they're defined as: #define BUFSIZ 1024
#define FILENAME_MAX 4096
#define FOPEN_MAX 1000
#define TMP_MAX 10000
#define L_tmpnam 20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm guessing he just copy-pasted one of the blocks above. Please don't submit code like this that is just copy-pasted from above without being checked. |
||
| } | ||
| else version( Darwin ) | ||
| { | ||
| enum | ||
|
|
@@ -292,6 +310,14 @@ else version( CRuntime_Bionic ) | |
| int _size; | ||
| } | ||
| } | ||
| else version( CRuntime_Musl ) | ||
| { | ||
| enum | ||
| { | ||
| EOF = -1, | ||
| } | ||
|
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete |
||
| else | ||
| { | ||
| static assert( false, "Unsupported platform" ); | ||
|
|
@@ -383,6 +409,16 @@ else version( CRuntime_Glibc ) | |
| /// | ||
| alias shared(_IO_FILE) FILE; | ||
| } | ||
| else version( CRuntime_Musl ) | ||
| { | ||
| struct fpos_t { | ||
| char[16] __opaque; | ||
| double __align; | ||
| } | ||
| struct _IO_FILE; | ||
| alias _IO_FILE _iobuf; | ||
| alias shared(_IO_FILE) FILE; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else version (CRuntime_Musl)
{
// http://git.musl-libc.org/cgit/musl/tree/include/stdio.h
union fpos_t
{
char[16] __opaque;
double __align;
}
struct _IO_FILE;
alias FILE = shared(_IO_FILE);
}
The real
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strictly speaking we don't really need to define the structures of any
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ZombineDev _iobuf is defined because it's used in phobos. |
||
| else version( Darwin ) | ||
| { | ||
| /// | ||
|
|
@@ -917,6 +953,20 @@ else version( CRuntime_Bionic ) | |
| /// | ||
| shared stderr = &__sF[2]; | ||
| } | ||
| else version( CRuntime_Musl ) | ||
| { | ||
| /// needs tail const | ||
| extern shared FILE* stdin; | ||
| /// | ||
| extern shared FILE* stdout; | ||
| /// | ||
| extern shared FILE* stderr; | ||
| enum { | ||
| _IOFBF = 0, | ||
| _IOLBF = 1, | ||
| _IONBF = 2, | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else version (CRuntime_Musl)
{
// http://git.musl-libc.org/cgit/musl/tree/include/stdio.h
///
extern shared FILE* stdin;
///
extern shared FILE* stdout;
///
extern shared FILE* stderr;
enum
{
_IOFBF = 0,
_IOLBF = 1,
_IONBF = 2,
}
} |
||
| else | ||
| { | ||
| static assert( false, "Unsupported platform" ); | ||
|
|
@@ -1416,6 +1466,30 @@ else version( CRuntime_Bionic ) | |
| /// | ||
| int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); | ||
| } | ||
| else version( CRuntime_Musl ) | ||
| { | ||
| import core.sys.posix.sys.types : off_t; | ||
| /// | ||
| int fseeko(FILE *, off_t, int); | ||
| @trusted | ||
| { | ||
| /// | ||
| void rewind(FILE* stream); | ||
| /// | ||
| pure void clearerr(FILE* stream); | ||
| /// | ||
| pure int feof(FILE* stream); | ||
| /// | ||
| pure int ferror(FILE* stream); | ||
| /// | ||
| int fileno(FILE *); | ||
| } | ||
|
|
||
| /// | ||
| int snprintf(scope char* s, size_t n, scope const char* format, ...); | ||
| /// | ||
| int vsnprintf(scope char* s, size_t n, scope const char* format, va_list arg); | ||
| } | ||
| else | ||
| { | ||
| static assert( false, "Unsupported platform" ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,6 +106,11 @@ else version (CRuntime_Bionic) | |
| /// | ||
| int strerror_r(int errnum, scope char* buf, size_t buflen); | ||
| } | ||
| else version (CRuntime_Musl) | ||
| { | ||
| /// | ||
| int strerror_r (int, char *, size_t); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. else version (CRuntime_Musl)
{
///
int strerror_r(int errnum, scope char* buf, size_t buflen);
} |
||
| /// | ||
| pure size_t strlen(scope const char* s); | ||
| /// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,6 +194,13 @@ else version( CRuntime_Bionic ) | |
| /// | ||
| extern __gshared const(char)*[2] tzname; | ||
| } | ||
| else version( CRuntime_Musl ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You also need to add the following definition at the start of the file: else version (CRuntime_Musl)
{
enum clock_t CLOCKS_PER_SEC = 1_000_000;
} |
||
| { | ||
| /// | ||
| void tzset(); // non-standard | ||
| /// | ||
| extern __gshared const(char)*[2] tzname; // non-standard | ||
| } | ||
| else | ||
| { | ||
| static assert(false, "Unsupported platform"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that hitting
static assert(0)can be annoying at the beginning when you just want see how far you can go, but to get your changes to into merge-able state, you need to fill out all emptyelse version (CRuntime_Musl) { }blocks that you added.In this case, looking at include/assert.h (from git.musl-libc.org) and the glibc version above, you need to add:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or alternately, just leave empty blocks out of this pull for now, except for those that assert without them. In this case, you could just add a TODO comment here, as this is only needed for the
betterCsupport. I don't know that adding__assert_failalone does much, as dmd likely only calls__assert.