RejectedSoftware Forums

Sign up

Pages: 1 2

Running vibe.d project with DUB using custom main()

Hello,

I've tried doing this but it complains about multiple "main" functions.

Is it possible to do? The project works if I invoke vibe manually.

Thanks,
Matej

Re: Running vibe.d project with DUB using custom main()

Am 18.04.2013 20:54, schrieb Matej Nanut:

Hello,

I've tried doing this but it complains about multiple "main" functions.

Is it possible to do? The project works if I invoke vibe manually.

Thanks,
Matej

Currently it is necessary to add {"versions": ["VibeCustomMain"]} to
the project's package.json.

I hope to find a more elegant solution at some point, but the issue is
that the previous "include vibe.d normally and vibe.vibe for custom
main" approach makes it necessary to use rdmd or a similar dependency
based build system - and that conflicts with the way the IDEs handle the
build process...

Re: Running vibe.d project with DUB using custom main()

On Thu, 18 Apr 2013 21:23:32 +0200, Sönke Ludwig wrote:

Currently it is necessary to add {"versions": ["VibeCustomMain"]} to
the project's package.json.

Thanks! I'll just use "shared static this()" for now though. I really had no good reason to use custom main(), and the original idea is very D-ish.

Another problem creeped up though, I get an assert error when using normal build (not -release). Also, if I specify -release as a dflag in package.json, DUB complains about it, saying I should call it instead with --build=release. Can this be set as a default in package.json?

This is the error:

[B7235F80:B7235F00 ERR] Error after page has been written: core.exception.AssertError@diet.d(95): Assertion failure
----------------
/tmp/dub/3857266684/Gaol(_d_assert+0x12) [0x8282092]
/tmp/dub/3857266684/Gaol(void vibe.templ.diet.compileDietFileCompatV!("javarun.dt", javarun.JavaRunVM, "model").compileDietFileCompatV(vibe.core.stream.OutputStream, void*, TypeInfo[])+0x95) [0x82693d1]
/tmp/dub/3857266684/Gaol(void vibe.http.server.HttpServerResponse.renderCompat!("javarun.dt", javarun.JavaRunVM, "model").renderCompat(, ...)+0x88) [0x826283c]
/tmp/dub/3857266684/Gaol(void javarun.renderJavaRun(vibe.http.server.HttpServerResponse, const(javarun.JavaRunVM))+0x21) [0x81b9db1]
/tmp/dub/3857266684/Gaol(void javarun.showJavaRun(vibe.http.server.HttpServerRequest, vibe.http.server.HttpServerResponse)+0x10a) [0x81b98e6]
/tmp/dub/3857266684/Gaol(void std.functional.DelegateFaker!(void function(vibe.http.server.HttpServerRequest, vibe.http.server.HttpServerResponse)*).DelegateFaker.doIt(vibe.http.server.HttpServerRequest, vibe.http.server.HttpServerResponse)+0x45) [0x821b71d]
/tmp/dub/3857266684/Gaol(void vibe.http.router.UrlRouter.handleRequest(vibe.http.server.HttpServerRequest, vibe.http.server.HttpServerResponse)+0x102) [0x825de6e]
/tmp/dub/3857266684/Gaol(bool vibe.http.server.handleRequest(vibe.core.stream.Stream, immutable(char)[], vibe.http.server.HTTPServerListener, ref vibe.http.server.HttpServerSettings, ref bool)+0xe85) [0x8261c99]
/tmp/dub/3857266684/Gaol(void vibe.http.server.handleHttpConnection(vibe.core.net.TcpConnection, vibe.http.server.HTTPServerListener)+0x9d) [0x8260d85]
/tmp/dub/3857266684/Gaol(void vibe.http.server.listenHttpPlain(vibe.http.server.HttpServerSettings, void delegate(vibe.http.server.HttpServerRequest, vibe.http.server.HttpServerResponse)).void doListen(vibe.http.server.HttpServerSettings, vibe.http.server.HTTPServerListener, immutable(char)[]).void __lambda72(vibe.core.net.TcpConnection)+0x23) [0x825e65b]
/tmp/dub/3857266684/Gaol(extern (C) nothrow void vibe.core.drivers.libevent2_tcp.onConnect(int, short, void*).void ClientTask.execute()+0x20e) [0x81c1b06]
/tmp/dub/3857266684/Gaol(void vibe.core.core.CoreTask.run()+0x99) [0x822980d]
/tmp/dub/3857266684/Gaol(void core.thread.Fiber.run()+0x21) [0x82a8501]
/tmp/dub/3857266684/Gaol(fiber_entryPoint+0x4e) [0x82a843e]
[(nil)]
Error: Program exited with code -11

Re: Running vibe.d project with DUB using custom main()

On Thu, 18 Apr 2013 19:52:35 GMT, Matej Nanut wrote:

(...)

This is the error:

[B7235F80:B7235F00 ERR] Error after page has been written: core.exception.AssertError@diet.d(95): Assertion failure
(...)

Looks like the actualy type of a parameter passed to req.renderCompat!() is different that what was passed in the template argument (which was not easy to find in the source code because the assertion happens inside of a string mixin...). I've made a commit with proper error messages for all assertions in the Diet compiler.

Re: Running vibe.d project with DUB using custom main()

But why does it not happen on -release?

Re: Running vibe.d project with DUB using custom main()

Can it be because the parameter passed into renderCompat is actually an "in javaRunVM" instead of a plain "javaRunVM"?

Re: Running vibe.d project with DUB using custom main()

Must be ... if I use "render" (not "renderCompat") it works fine.

But how would I specify the compile-time argument correctly? If I use "typeof(model)" (or "const JavaRunVM") it errors out with:

Compiling diet template 'javarun.dt' (compat)...
diet.d(93): Error: cannot modify const expression model
/usr/include/d/druntime/import/core/stdc/stdarg.d(214): Error: cannot modify const expression parmn
/usr/include/d/druntime/import/core/stdc/stdarg.d(200): Error: template instance core.stdc.stdarg.va_arg!(const(JavaRunVM)) error instantiating
diet.d(96):        instantiated from here: va_arg!(const(JavaRunVM))
.dub/packages/vibe-d/source/vibe/http/server.d(844):        instantiated from here: compileDietFileCompatV!("javarun.dt", const(JavaRunVM),"model")
source/javarun.d(128):        instantiated from here: renderCompat!("javarun.dt", const(JavaRunVM), "model")
diet.d(96): Error: template instance core.stdc.stdarg.va_arg!(const(JavaRunVM)) error instantiating
.dub/packages/vibe-d/source/vibe/http/server.d(844):        instantiated from here: compileDietFileCompatV!("javarun.dt", const(JavaRunVM),"model")
source/javarun.d(128):        instantiated from here: renderCompat!("javarun.dt", const(JavaRunVM), "model")
diet.d(96): Error: cannot modify const expression model
.dub/packages/vibe-d/source/vibe/http/server.d(844): Error: template instance vibe.templ.diet.compileDietFileCompatV!("javarun.dt", const(JavaRunVM),"model") error instantiating
source/javarun.d(128):        instantiated from here: renderCompat!("javarun.dt", const(JavaRunVM), "model")
source/javarun.d(128): Error: template instance vibe.http.server.HttpServerResponse.renderCompat!("javarun.dt", const(JavaRunVM), "model") error instantiating

Re: Running vibe.d project with DUB using custom main()

Am 19.04.2013 18:44, schrieb Matej Nanut:

Can it be because the parameter passed into renderCompat is actually an "in javaRunVM" instead of a plain "javaRunVM"?

Yes, that sounds very likely. The reason is that const(T) and T have
a different TypeInfo and this is used in the assertion to check the
type. Maybe the assertion should rather use Variant.convertTo and be
less strict about the actual type...

BTW the reason for release builds working is simply because assertions
are disabled in release mode and Variant.get presumably is able to
implicitly convert the value to non-cost.

I'll go ahead and change the assertion to use convertsTo.

Re: Running vibe.d project with DUB using custom main()

Am 19.04.2013 19:39, schrieb Sönke Ludwig:

Am 19.04.2013 18:44, schrieb Matej Nanut:

Can it be because the parameter passed into renderCompat is actually an "in javaRunVM" instead of a plain "javaRunVM"?

Yes, that sounds very likely. The reason is that const(T) and T have
a different TypeInfo and this is used in the assertion to check the
type. Maybe the assertion should rather use Variant.convertTo and be
less strict about the actual type...

BTW the reason for release builds working is simply because assertions
are disabled in release mode and Variant.get presumably is able to
implicitly convert the value to non-cost.

I'll go ahead and change the assertion to use convertsTo.

Okay looking closer, this happens in the code path where no Variant is
involved at all, so using convertsTo is not an option. I've opened a
ticket with a possible alternative approach instead:
https://github.com/rejectedsoftware/vibe.d/issues/219

Re: Running vibe.d project with DUB using custom main()

But why doesn't the actual type work? Why musn't it be const?

Using just "render" seems to infer the types correctly?

Pages: 1 2