SPVM-Go
view release on metacpan or search on metacpan
lib/SPVM/Go/Coroutine.config view on Meta::CPAN
# Copyright (c) 2023 Yuki Kimoto
# MIT License
use strict;
use warnings;
use Config;
use SPVM::Builder::Config;
sub get_coro_define {
# Copied from Coro/Makefile.PL
sub have_inc($) {
scalar grep -r "$_/$_[0]", $Config{usrinc}, split / /, $Config{incpth}
}
my $iface;
my $LIBS = [];
# default to assembly on x86 and x86_64 sometimes
my $iface_asm = $Config{archname} =~ /^(i[3456]86|amd64|x86_64|MSWin32-x64)-/ ? "a" : undef;
# detect whether this perl is threaded, for those broken operating
# systems that need it.
my $pthread = $Config{libs} =~ /-lpthread/
|| $Config{ldflags} =~ /-pthread/
|| $Config{archname} =~ /-thread/;
if (exists $ENV{CORO_INTERFACE}) {
$iface = $ENV{CORO_INTERFACE};
} elsif ($^O =~ /mswin32/i) {
# nothing works, really, without deep hacks
$iface = "f";
} elsif ($^O =~ /cygwin/) {
# cygwin true to its form, be an order of magnitutde slower,
# while using twice the amount of ram. but it works! yeah!
$iface = "p";
} elsif ($^O =~ /irix/) {
# sigaltstack works like sigstack, i.e. expects stack pointer, not stack base
# but wikipeida lists it as 100% posix compliant. geeeee.
$iface = "i";
} elsif ($^O =~ /linux/) {
# everything "just works", as expected
$iface = $iface_asm || "s";
} elsif ($^O =~ /freebsd/) {
# FreeBSD 4.x has ucontext.h but no makecontext et al. (see BUGS section of
# man context).
#
# FreeBSD 6.2 has marginally working ucontext, setjmp and asm, but
# some 5.8.8's barf when threaded due to broken threading.
$iface = $iface_asm || "s";
} elsif ($^O =~ /netbsd/) {
# netbsd is totally broken (pthreads are incompatible with ucontext or
# other stack switching mechanisms) therefore, default to pthread -
# hey, it might actually work, with some hacks.
$iface = "p";
if (!$pthread) {
# ugh, pthreads need to be linked into the main program :/
$iface = $iface_asm || "s";
}
} elsif ($^O =~ /(openbsd|mirbsd)/) {
lib/SPVM/Go/Coroutine.config view on Meta::CPAN
# has ever been created, then the program is bound to a kernel-scheduled
# entity. get that? GET THAT?)
$iface = "p";
}
} elsif ($^O =~ /solaris/) {
# setjmp, ucontext seem to work, as well as asm
$iface = $iface_asm || "s";
} elsif ($^O =~ /darwin/) {
# assembler doesn't support .type
# ucontext is of course totally broken (it just crashes)
# surprisingly, pthreads seem to work
$iface = "s";
} elsif ($^O =~ /dragonfly/) {
# ucontext is totally broken on dragonfly bsd:
# Fatal error 'siglongjmp()ing between thread contexts is undefined by POSIX 1003.1
$iface = "s";
} elsif (have_inc "ucontext.h") { # shame on this heuristic
$iface = "u";
} else {
$iface = "s";
}
my $DEFINE;
if ($iface eq "u") {
$DEFINE .= " -DCORO_UCONTEXT";
} elsif ($iface eq "s") {
$DEFINE .= " -D_FORTIFY_SOURCE=0";
$DEFINE .= " -DCORO_SJLJ";
} elsif ($iface eq "l") {
$DEFINE .= " -DCORO_LINUX";
} elsif ($iface eq "i") {
$DEFINE .= " -DCORO_IRIX";
} elsif ($iface eq "w") {
$DEFINE .= " -DCORO_LOSER";
} elsif ($iface eq "f") {
$DEFINE .= " -DCORO_FIBER";
} elsif ($iface eq "a") {
$DEFINE .= " -DCORO_ASM";
} elsif ($iface eq "p") {
$DEFINE .= " -DCORO_PTHREAD";
$LIBS = ["-lpthread"];
} else {
goto retry;
}
my $stacksize = $^O eq "linux" && $] < 5.008008 ? 128 * 1024 : 16384;
$DEFINE .= " -DCORO_STACKSIZE=$stacksize";
return $DEFINE;
}
my $config = SPVM::Builder::Config->new_gnu99(file => __FILE__);
my $coro_define = &get_coro_define();
# TODO: why do heading spaces have an compile error?
$coro_define =~ s/^ //;
my @coro_define = split(/\s+/, $coro_define);
$config->add_ccflag(@coro_define);
my @source_files = qw(
coro.c
);
$config->add_source_file(@source_files);
$config;
( run in 1.641 second using v1.01-cache-2.11-cpan-39bf76dae61 )