Skip to content

Commit

Permalink
Add initial dub.sdl with stdx-allocator and stdx-checkedint
Browse files Browse the repository at this point in the history
  • Loading branch information
wilzbach committed Jun 22, 2018
1 parent 5814a92 commit 408edbe
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .circleci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ publictests()
make -f posix.mak -j$N publictests DUB=$DUB BUILD=$BUILD
}
# test stdx dub package
dub_package()
{
pushd test
dub -v --single dub_stdx_checkedint.d
dub -v --single dub_stdx_allocator.d
popd
}
case $1 in
install-deps) install_deps ;;
setup-repos) setup_repos ;;
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ obj/
.vscode

*.html

.dub/
libphobos_*
source/
44 changes: 44 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
@@ -1,6 +1,50 @@
name "phobos"
license "BSL-1.0"
description "D Standard Library"
authors "DLang Community"
copyright "Copyright © 1999-2018, The D Language Foundation"

targetType "library"
sourcePaths "std" "etc"
targetPath "generated"

subPackage {
name "checkedint"
targetType "library"
preGenerateCommands `rdmd --eval='
auto pkgDir = environment.get("DUB_PACKAGE_DIR");
auto destDir = pkgDir.buildPath("source", "stdx");
mkdirRecurse(destDir);
pkgDir.buildPath("std", "experimental", "checkedint.d")
.readText
.replace("std.experimental.checkedint", "stdx.checkedint")
.toFile(destDir.buildPath("checkedint.d"));'`
sourceFiles "source/stdx/checkedint.d"
importPaths "source"
}

// This meta package is needed because dub searches for the source files _before_ it evaluates preGenerateCommands
// However, it does run its dependencies _before_ searching through its source paths
subPackage {
name "allocator-generator"
targetType "none"
preGenerateCommands `rdmd --eval='
auto pkgDir = environment.get("DUB_PACKAGE_DIR");
auto destDir = pkgDir.buildPath("source", "stdx", "allocator");
auto srcDir = pkgDir.buildPath("std", "experimental", "allocator");
foreach (file; srcDir.dirEntries("*.d", SpanMode.depth)) {
auto destFile = file.replace(srcDir, destDir);
destFile.dirName.mkdirRecurse;
file.readText.replace("std.experimental.allocator", "stdx.allocator")
.toFile(destFile);
}
'`
}

subPackage {
name "allocator"
targetType "library"
dependency "phobos:allocator-generator" version="*"
sourcePaths "source/stdx/allocator"
importPaths "source"
}
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dub_stdx_allocator
dub_stdx_checkedint
13 changes: 13 additions & 0 deletions test/dub_stdx_allocator.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env dub
/++dub.sdl:
dependency "phobos:allocator" path=".."
+/

void main(string[] args)
{
import stdx.allocator.mallocator : Mallocator; // From latest Phobos
import std.stdio; // current phobos
auto buf = Mallocator.instance.allocate(10);
writeln("allocate: ", buf);
scope(exit) Mallocator.instance.deallocate(buf);
}
11 changes: 11 additions & 0 deletions test/dub_stdx_checkedint.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env dub
/++dub.sdl:
dependency "phobos:checkedint" path=".."
+/

void main(string[] args)
{
import stdx.checkedint; // From latest Phobos
import std.stdio; // DMD's Phobos
writeln("checkedint: ", 2.checked + 3);
}

0 comments on commit 408edbe

Please sign in to comment.