nedpals / vex

Easy-to-use, modular web framework built for V
https://nedpals.github.io/vex
MIT License
339 stars 28 forks source link

Compiling with -prod flag throws build error #54

Closed xD0135 closed 2 years ago

xD0135 commented 2 years ago

When trying to compile the following simple program using the -prod flag it throws a build error. Details are below:

Simple server:

# vex-server.v

module main

import nedpals.vex.router
import nedpals.vex.server
import nedpals.vex.ctx

fn main() {
    mut app := router.new()
    app.route(.get, '/', fn (req &ctx.Req, mut res ctx.Resp){
        res.send('', 200)
    })
    server.serve(app, 6789)
}

Compiling throws an error:

$ v -gc boehm -prod -o vex-server vex-server.v
==================
/tmp/v_1000/vex-server.15941504213174346917.tmp.c: In function ‘nedpals__vex__router__Router_receive’:
/tmp/v_1000/vex-server.15941504213174346917.tmp.c:27884:113: error: field name not in record or union initializer
27884 |                         ((string*)map_set(&req.headers, &(string[]){_SLIT("Content-Type")}, &(Array_string[]) { .data)[0]_SLIT("multipart/form-data") });
      |                                                                                                                 ^
/tmp/v_1000/vex-server.15941504213174346917.tmp.c:27884:113: note: (near initialization for ‘(anonymous)’)
/tmp/v_1000/vex-server.15941504213174346917.tmp.c:27884:118: error: expected ‘=’ before ‘)’ token
27884 |                         ((string*)map_set(&req.headers, &(string[]){_SLIT("Content-Type")}, &(Array_string[]) { .data)[0]_SLIT("multipart/form-data") });
      |                                                                                                                      ^
/tmp/v_1000/vex-server.15941504213174346917.tmp.c:27884:118: error: expected ‘}’ before ‘)’ token
27884 |                         ((string*)map_set(&req.headers, &(string[]){_SLIT("Content-Type")}, &(Array_string[]) { .data)[0]_SLIT("multipart/form-data") });
      |                                                                                                               ~      ^
/tmp/v_1000/vex-server.15941504213174346917.tmp.c:27884:151: error: expected ‘)’ before ‘}’ token
...
==================
(Use `v -cg` to print the entire error message)
nedpals commented 2 years ago

Can you post the output of v doctor so that I can check the version of V and your operating system?

nedpals commented 2 years ago

Just to follow up, this is more of an error to the V compiler but probably an outdated one hence the need to check your V version first.

benstigsen commented 2 years ago

Not an outdated one, still a V error, but not specific to Vex: https://github.com/vlang/v/issues/13431

xD0135 commented 2 years ago

Can you post the output of v doctor so that I can check the version of V and your operating system?

Here you go @nedpals:

$ v doctor
OS: linux, "Manjaro Linux"
Processor: 16 cpus, 64bit, little endian, Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
CC version: cc (GCC) 11.2.0

getwd: /home/user/Downloads/pewpew
vmodules: /home/user/.vmodules
vroot: /home/user/Downloads/v
vexe: /home/user/Downloads/v/v
vexe mtime: 2022-04-03 03:06:09
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 71dc6c2

Git version: git version 2.35.1
Git vroot status: weekly.2022.13-37-g71dc6c22 (9 commit(s) behind V master)
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 3654d6a8
nedpals commented 2 years ago

Thanks! This issue also persists on my side as well with the latest version of V. I have pushed @BenStigsen 's workaround for now (https://github.com/nedpals/vex/commit/8d5768c1b34d8114ce89facf850a0c4eba64e86c). :smiley:

xD0135 commented 2 years ago

Thanks @nedpals. I think you should also add a compilation test in your Action to detect potential future regressions