rescript-compiler icon indicating copy to clipboard operation
rescript-compiler copied to clipboard

Apply `-bs-g` flag via environment variable

Open alex35mil opened this issue 4 years ago • 41 comments

As per Discord discussion, to avoid accidental production builds with -bs-g applied via config, apply it via environment variable instead.

alex35mil avatar Aug 01 '19 05:08 alex35mil

Do you use debug build by default, how about generating .g.js for -bs-g?

bobzhang avatar Aug 03 '19 02:08 bobzhang

Do you use debug build by default?

Currently, I turn it on occasionally, when I need to inspect something at runtime, so not by default.

how about generating .g.js for -bs-g

Doesn't it introduce the same issue that it's required to change sources to switch the build? (e.g. change imports in js files)

alex35mil avatar Aug 16 '19 05:08 alex35mil

I would like this (or something similar) as well. I'm starting a new project and hoping to enable -bs-g by default in the early stages, but eventually we'll need a production output mode and it would be a shame to need bsconfig.json adjustments to toggle it.

How about a command line argument to bsb that turns on the -bs-g compiler flag? That would also allow it to be used on demand or (in my case) added to a "dev build" command.

TheSpyder avatar Aug 26 '19 17:08 TheSpyder

@TheSpyder Just fyi, flag was the first thing proposed in Discord discussion but @bobzhang preferred env var way back then.

alex35mil avatar Aug 27 '19 02:08 alex35mil

I can still vote for a flag as my preference 😉

An environment var would be fine, though, I'd just set it temporarily e.g. BS_DEBUG=true bsb instead of bsb -debug

TheSpyder avatar Aug 27 '19 07:08 TheSpyder

I find bs-g very useful and always have it on in my bsconfig.json. I strip it away using sed for production builds.

If this is going to be implemented, I think it would be useful to have an environment variable similar to "DUNE_PROFILE" instead of one that only turns dev mode on.

ozanmakes avatar Aug 27 '19 08:08 ozanmakes

strip it away using sed for production builds

Exactly. I don't mind how it's implemented, as long as I don't have to patch the config in a build script.

TheSpyder avatar Aug 27 '19 08:08 TheSpyder

Anything would be better than sed-ing the config for production build. Who is gonna make the decision here? @bobzhang?

erykpiast avatar Mar 11 '20 06:03 erykpiast

I'm reaching the point where I just want a way to specify a completely different bsconfig.json for my production builds

TheSpyder avatar Mar 11 '20 10:03 TheSpyder

I'm happy to pick up this, do we agreed on it?

Seems like having 2 different bsconfigs it's a pretty common scenario, rather than one env variable that toggles the bs-g. But both are compatible, so, can I just try to create a draft of this?

davesnx avatar Apr 30 '20 09:04 davesnx

On vacation, will have a look later

bobzhang avatar May 01 '20 01:05 bobzhang

how about using bsb -dev and pickup bsconfig.dev.json, would it complicate things too much?

bobzhang avatar May 07 '20 03:05 bobzhang

@bobzhang that would be awesome!

For bonus points, it would be amazing if bsconfig.dev.json could be a partial config and only overwrite options it specifies (falling back to bsconfig.json. That can be tricky with nested objects, but even a simple shallow overwrite setup would be better than requiring near-complete duplication of bsconfig.json.

IMO that would make it less complicated to understand as well.

TheSpyder avatar May 07 '20 05:05 TheSpyder

+ for shallow overwrite

alex35mil avatar May 07 '20 05:05 alex35mil

@bobzhang that would be awesome!

For bonus points, it would be amazing if bsconfig.dev.json could be a partial config and only overwrite options it specifies (falling back to bsconfig.json. That can be tricky with nested objects, but even a simple shallow overwrite setup would be better than requiring near-complete duplication of bsconfig.json.

IMO that would make it less complicated to understand as well.

Also would be super amazing to have bsconfig.prod.json and any other bsconfig.ENV.json that uses bsconfig.json as a base config

Coobaha avatar May 07 '20 05:05 Coobaha

Also would be super amazing to have bsconfig.prod.json and any other bsconfig.ENV.json that uses bsconfig.json as a base config

For complicated needs, perhaps, but one step at a time. I'd rather see --dev and bsconfig.dev.json now than wait until bob has time to work on a fully configurable solution.

TheSpyder avatar May 07 '20 06:05 TheSpyder

@bobzhang to avoid possible conflicts, I think something like bsb -config dev to pick up bsconfig.dev.json.

yawaramin avatar May 26 '20 23:05 yawaramin

except -bs-g, do we have more use cases? Note -bs-g is a bit different, for this flag, when you turn it on, in general you would like to make it effective in your dependency as well. This is related to ppx-dev-flags https://github.com/BuckleScript/bucklescript/issues/3761, however, it is slightly different, for dependencies, you don't want it to be triggered

bobzhang avatar Jun 03 '20 06:06 bobzhang

except -bs-g, do we have more use cases?

Different warnings configuration for dev and prod builds.

alex35mil avatar Jun 03 '20 06:06 alex35mil

-- sorry if you get double posts

Different warnings configuration for dev and prod builds.

This is actually not suggested, why do you want that? Note you can turn off some warnings for each file for convenience

bobzhang avatar Jun 03 '20 06:06 bobzhang

This is actually not suggested, why do you want that? Note you can turn off some warnings for each file for convenience

In development, having some warnings as warnings but in production turning them into hard errors. Like if there is a big match and I want to try one branch at runtime w/o implementing/mocking others. I don't like adding annotation in this case b/c it is easy to forget to remove one.

alex35mil avatar Jun 03 '20 07:06 alex35mil

I'm sure I've requested different warnings for dev and prod 🤔 maybe that was just a Discord discussion, sorry for not recording it here. I would very much like to change all of my configured warnings to errors in production builds.

I'm also planning to work on some conditional compilation to remove debug code from production; that will involve using -bs-D to turn debug on in development.

The PPX dev adjustments you mentioned is something I'd like to look into in the future, but have never considered due to the difficulty of toggling command line arguments. For example ppx-expect, which will compile tests written inside production source code for dev, but produce no code for those tests in production (or at least that's how I think it works, I've never really tried it).

TheSpyder avatar Jun 03 '20 09:06 TheSpyder

@alexfedoseev I think it was suggested in the Discord that OCAMLRUNPARAM can be used to set the warnings on each run of bsb.

Anyway, if we are indeed going for a generalized bsconfig.[ENV].json approach, where the [ENV] could be passed as a command-line bsb option, it would solve a lot of issues.

yawaramin avatar Jun 03 '20 15:06 yawaramin

I have the same use case as @TheSpyder, where I want to vary -bs-D flags somehow. Interpolating env vars in bsconfig.json could be another solution to that particular problem.

joprice avatar Jun 03 '20 15:06 joprice

@yawaramin Yeah, this is how I address this case currently. But since this issue is being discussed I'd prefer doing everything via configs rather than pretty cryptic OCAMLRUNPARAM.

alex35mil avatar Jun 03 '20 19:06 alex35mil

@TheSpyder -bs-D seems to be a valid use case, I am wondering that -bs-g automatically brinings -bs-D DEBUG in scope, would that cover most of your use cases?

bobzhang avatar Jun 04 '20 01:06 bobzhang

@bobzhang that would be fine, yes

TheSpyder avatar Jun 05 '20 09:06 TheSpyder

I'm only just getting into the conditional compilation I was talking about back in June, and it looks like -bs-g now sets -bs-D DEBUG? And it has done so for a while, since I'm still on v8.0.3?

TheSpyder avatar Oct 08 '20 04:10 TheSpyder

This worked perfectly, now I just need a way to control -bs-g without editing bsconfig.json so I can remove it in CI :)

TheSpyder avatar Oct 09 '20 05:10 TheSpyder

-- sorry if you get double posts

Different warnings configuration for dev and prod builds.

This is actually not suggested, why do you want that? Note you can turn off some warnings for each file for convenience

How would one add an annotation to disable a specific error for a specific file?

The following:

[@bs.config { warnings: { error: "+A-3-44-102-103" } } ]

Produces: Screen Shot 2020-12-02 at 2 35 03 PM

nsculli7 avatar Dec 02 '20 22:12 nsculli7