www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Hipreme's #8 Tip of the day - Using custom runtime with dub projects

reply Hipreme <msnmancini hotmail.com> writes:
I have been working with WebAssembly for at least 1 entire month 
into getting my entire Game Engine and DRuntime ported to it. As 
I'm almost reaching the point of the new announcement, I come 
here to show how I've done DUB's dependency compatibility with a 
custom runtime.

The way to use dub's packages is by using the DFLAGS. With 
DFLAGS, I can set the import path to my own DRuntime and own std. 
That way I can make the dependencies behave more or less the 
same, this is an example of what is being done now:


```
set DFLAGS=-I=%HIPREME_ENGINE%/modules/d_std/source ^
-I=%HIPREME_ENGINE%/build/wasm/runtime/webassembly/arsd-webassembly ^
-preview=shortenedMethods ^
-L-allow-undefined ^
-fvisibility=hidden ^
-d-version=CarelessAlocation

dub build --build=debug -c wasm  
--arch=wasm32-unknown-unknown-wasm
```


So, when dub tried to build their dependencies, your custom 
runtime overrides D's default ones. In that case I'm overriding 
both D std and D core/** and object.d

Keep in mind that you'll probably need to setup some env 
variables such as mine done for making your script a little more 
portable to other developer's PCs. I would really like if there 
was a way to define global dflags on dub though.
Jan 22 2023
parent reply evilrat <evilrat666 gmail.com> writes:
On Sunday, 22 January 2023 at 16:57:56 UTC, Hipreme wrote:
 The way to use dub's packages is by using the DFLAGS. With 
 DFLAGS, I can set the import path to my own DRuntime and own 
 std. That way I can make the dependencies behave more or less 
 the same, this is an example of what is being done now:

 Keep in mind that you'll probably need to setup some env 
 variables such as mine done for making your script a little 
 more portable to other developer's PCs. I would really like if 
 there was a way to define global dflags on dub though.
Can't you just use env variable[1] and put into dub dflags like this? https://github.com/Superbelko/ohmygentool/blob/cc75d915a8df8bdc2bba628df305d421151994a1/dub.json#L11 _(note that some of the listed predefines doesn't work in some sections though, a bug maybe?)_ [1] https://dub.pm/package-format-json.html#environment-variables
Jan 22 2023
parent reply Hipreme <msnmancini hotmail.com> writes:
On Sunday, 22 January 2023 at 17:06:13 UTC, evilrat wrote:
 On Sunday, 22 January 2023 at 16:57:56 UTC, Hipreme wrote:
 The way to use dub's packages is by using the DFLAGS. With 
 DFLAGS, I can set the import path to my own DRuntime and own 
 std. That way I can make the dependencies behave more or less 
 the same, this is an example of what is being done now:

 Keep in mind that you'll probably need to setup some env 
 variables such as mine done for making your script a little 
 more portable to other developer's PCs. I would really like if 
 there was a way to define global dflags on dub though.
Can't you just use env variable[1] and put into dub dflags like this? https://github.com/Superbelko/ohmygentool/blob/cc75d915a8df8bdc2bba628df305d421151994a1/dub.json#L11 _(note that some of the listed predefines doesn't work in some sections though, a bug maybe?)_ [1] https://dub.pm/package-format-json.html#environment-variables
Nope. Those DFLAGS environment variable is used to affect projects such as my dependencies. For example, my dependency needs to be built using my own runtime. The dflags defined in the dub.json only affect the current project, not its dependencies
Jan 22 2023
parent evilrat <evilrat666 gmail.com> writes:
On Sunday, 22 January 2023 at 18:16:35 UTC, Hipreme wrote:
 Nope. Those DFLAGS environment variable is used to affect 
 projects such as my dependencies. For example, my dependency 
 needs to be built using my own runtime. The dflags defined in 
 the dub.json only affect the current project, not its 
 dependencies
Ah ok, got it, the compiler will fetch them for a whole session no matter what is currently being built. Though this approach will make it harder to anyone who might want to use your project/library if this requirement remains for a user's project.
Jan 22 2023