Is there any plan for a dependency-free subset of "core" runtime?

kinke noone at nowhere.com
Thu Jul 19 18:16:17 UTC 2018


On Thursday, 19 July 2018 at 12:44:30 UTC, Radu wrote:
> ---
> int foo()
> {
>     import std.algorithm, std.range;
>     auto r = 100.iota.stride(2).take(5);
>     return r.sum();
> }
> ---
> ldc2 -mtriple=wasm32-unknown-unknown-wasm -betterC 
> -link-internally -L-allow-undefined -release -Os wasm.d
> ldc\bin\..\import\core\stdc\stdio.d(31): Error: module 
> `core.stdc.stdint` import intptr_t not found
> ldc\bin\..\import\core\stdc\stdio.d(1149): Error: undefined 
> identifier FILE
> ....
>
> This is a prime example of stuff that should just workTM on 
> targets like that. I would like to submit some fixes but I 
> think there needs to be a more systematic approach on making 
> more core APIs modular.

Removing some superfluous explicit druntime dependencies from 
Phobos would be a start. Your (nice) example compiles fine with 
this 4-lines Phobos hack:

---
diff --git a/std/ascii.d b/std/ascii.d
index 8622785b1..b3815cafd 100644
--- a/std/ascii.d
+++ b/std/ascii.d
@@ -105,10 +105,10 @@ enum LetterCase : bool
  /// Newline sequence for this system.
  version(Windows)
      immutable newline = "\r\n";
-else version(Posix)
+else// version(Posix)
      immutable newline = "\n";
-else
-    static assert(0, "Unsupported OS");
+//else
+//    static assert(0, "Unsupported OS");


  /++
diff --git a/std/typecons.d b/std/typecons.d
index 203ab05f4..49edebfaf 100644
--- a/std/typecons.d
+++ b/std/typecons.d
@@ -68,7 +68,8 @@ Authors:   $(HTTP erdani.org, Andrei 
Alexandrescu),
   */
  module std.typecons;

-import core.stdc.stdint : uintptr_t;
+//import core.stdc.stdint : uintptr_t;
+alias uintptr_t = size_t;
  import std.format : singleSpec, FormatSpec, formatValue;
  import std.meta; // : AliasSeq, allSatisfy;
  import std.range.primitives : isOutputRange;
---

Importing core.stdc.stdint for `uintptr_t` in std.typecons is 
particularly troublesome and totally unnecessary. It leads to 
importing (see -v output):

core.stdc.stdint
core.stdc.config
core.stdc.stddef
core.stdc.signal
core.stdc.wchar_
core.stdc.stdarg
core.stdc.stdio
core.stdc.time

whereas after the hack, it's only `core.stdc.stdarg`, and no 
core.stdc.* hacks for `version(WebAssembly)` are required to 
import std.algorithm and std.range.

[I'll open a PR for std.typecons.]


More information about the Digitalmars-d-learn mailing list