Skip to content

Commit

Permalink
Use libjulia for Libtask (#2087)
Browse files Browse the repository at this point in the history
* Use libjulia for Libtask

* Apply all flags from Libtask.jl

* Remove conditionals

* Set version number manually
  • Loading branch information
devmotion authored Nov 19, 2020
1 parent e10ffd2 commit a9bd57b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 92 deletions.
62 changes: 0 additions & 62 deletions L/Libtask/build_dylib.sh

This file was deleted.

77 changes: 47 additions & 30 deletions L/Libtask/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -1,52 +1,69 @@
# Note that this script can accept some limited command-line arguments, run
# `julia build_tarballs.jl --help` to see a usage message.
using Pkg
using BinaryBuilder
using BinaryBuilder, Pkg

name = "Libtask"
version = v"0.3.2"
commit_id = "fbe338053f402d76524d0a01f3796dd7da90b781"
julia_version = v"1.3.1"

# see https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/336
# ENV["CI_COMMIT_TAG"] = ENV["TRAVIS_TAG"] = "v" * string(version)
name = "Libtask"
version = v"0.4.0"

# Collection of sources required to build Libtask
sources = [
"https://github.com/TuringLang/Libtask.jl.git" => commit_id,
DirectorySource("./bundled"),
]

# Bash recipe for building across all platforms
script_file = joinpath(@__DIR__, "build_dylib.sh")
if !isfile(script_file) # when run generate_buildjl.jl
script_file = joinpath(@__DIR__, "L/Libtask/build_dylib.sh")
end
script = read(script_file, String)
script = raw"""
# create output directory
mkdir -p "${libdir}"
# compile library
cd "${WORKSPACE}/srcdir/"
CFLAGS="-I${includedir} -I${includedir}/julia -O2 -shared -std=gnu99 -fPIC"
if [[ "${target}" == i686-* ]]; then
CFLAGS="${CFLAGS} -march=pentium4"
fi
if [[ "${target}" == *-mingw* ]]; then
CFLAGS="${CFLAGS} -Wl,--export-all-symbols"
elif [[ "${target}" == *-linux-* ]]; then
CFLAGS="${CFLAGS} -Wl,--export-dynamic"
fi
LDFLAGS="-L${libdir} -ljulia"
if [[ "${target}" == *-mingw* ]]; then
LDFLAGS="${LDFLAGS} -lopenlibm"
fi
$CC $CFLAGS $LDFLAGS task.c -o "${libdir}/libtask_julia.${dlext}"
# install license
install_license LICENSE.md
"""

# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
platforms = [
Platform("i686", "linux"; libc="glibc"),
Platform("x86_64", "linux"; libc="glibc"),
Platform("powerpc64le", "linux"; libc="glibc"),
# Platform("armv7l", "linux"; libc="glibc"),
Platform("aarch64", "linux"),
Platform("x86_64", "macos"),
Platform("i686", "windows"),
Platform("x86_64", "windows")
]
platforms = supported_platforms()

# skip i686 musl builds (not supported by libjulia_jll)
filter!(p -> !(Sys.islinux(p) && libc(p) == "musl" && arch(p) == "i686"), platforms)

# skip PowerPC builds in Julia 1.3 (not supported by libjulia_jll)
if julia_version < v"1.4"
filter!(p -> !(Sys.islinux(p) && arch(p) == "powerpc64le"), platforms)
end

# The products that we will ensure are always built
products = [
LibraryProduct("libtask_v1_0", :libtask_v1_0)
LibraryProduct("libtask_v1_1", :libtask_v1_1)
LibraryProduct("libtask_v1_2", :libtask_v1_2)
LibraryProduct("libtask_v1_3", :libtask_v1_3)
LibraryProduct("libtask_julia", :libtask_julia),
]

# Dependencies that must be installed before this package can be built
dependencies = [
BuildDependency(PackageSpec(name="libjulia_jll", version=julia_version)),
]

# Build the tarballs, and possibly a `build.jl` as well.
# build_file = "products/build_$(name).v$(version).jl"
build_tarballs(ARGS, name, version, sources,
script, platforms, products, dependencies)
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
julia_compat = "~$(julia_version.major).$(julia_version.minor)",
lock_microarchitecture = false)
21 changes: 21 additions & 0 deletions L/Libtask/bundled/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 The Turing Language

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
74 changes: 74 additions & 0 deletions L/Libtask/bundled/task.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
task.c
task copying (aka continuation) for lightweight processes (symmetric coroutines)
*/

#include "julia.h"

// Workaround for JuliaLang/julia#32812
jl_task_t *vanilla_get_current_task(void)
{
jl_ptls_t ptls = jl_get_ptls_states();
return (jl_task_t*)ptls->current_task;
}


jl_task_t *jl_enable_stack_copying(jl_task_t *t)
{
if (!t->copy_stack) {
jl_ptls_t ptls = jl_get_ptls_states();
t->copy_stack = 1;
t->bufsz = 0;
memcpy(&t->ctx, &ptls->base_ctx, sizeof(t->ctx));
}
return t;
}

jl_task_t *jl_clone_task(jl_task_t *t)
{
jl_ptls_t ptls = jl_get_ptls_states();
jl_task_t *newt = (jl_task_t*)jl_gc_allocobj(sizeof(jl_task_t)); // More efficient
//jl_task_t *newt = (jl_task_t*)jl_new_task(t->start, t->ssize); // Less efficient
memset(newt, 0, sizeof(jl_task_t));
jl_set_typeof(newt, jl_task_type);
newt->stkbuf = NULL;
newt->gcstack = NULL;
JL_GC_PUSH1(&newt);

newt->state = t->state;
newt->start = t->start;
newt->tls = jl_nothing;
newt->logstate = ptls->current_task->logstate;
newt->result = jl_nothing;
newt->donenotify = jl_nothing;
newt->exception = jl_nothing;
newt->backtrace = jl_nothing;
newt->eh = t->eh;
newt->gcstack = t->gcstack;
newt->tid = t->tid; // TODO: need testing
newt->started = t->started; // TODO: need testing


newt->copy_stack = t->copy_stack;
memcpy((void*)newt->ctx.uc_mcontext, (void*)t->ctx.uc_mcontext, sizeof(jl_jmp_buf));
newt->queue = t->queue;
newt->sticky = t->sticky;

if (t->stkbuf) {
// newt->stkbuf = allocb(t->bufsz);
// newt->bufsz = t->bufsz;
// memcpy(newt->stkbuf, t->stkbuf, t->bufsz);
// workaround, newt and t will get new stkbuf when savestack is called.
t->bufsz = 0;
newt->bufsz = 0;
newt->stkbuf = t->stkbuf;
} else {
newt->bufsz = 0;
newt->stkbuf = NULL;
}

JL_GC_POP();
jl_gc_wb_back(newt);

return newt;
}

0 comments on commit a9bd57b

Please sign in to comment.