bsansouci / bsb-native

Build system for OCaml/Reason
Other
245 stars 10 forks source link

Allow custom config file (not just bsconfig.json) #5

Open jaredly opened 7 years ago

jaredly commented 7 years ago

Would be awesome to be able to specify e.g. -config native.json, for apps that have a native component (e.g. a server) and a js component (e.g. the client).

bsansouci commented 7 years ago

What options do you have that you'd like to have different between JS and native?

jaredly commented 7 years ago

ppx-flags was the one I wanted to be different

bsansouci commented 7 years ago

I could make that happen. Is it that your codebase uses one ppx but you want to swap the implementation beteeen JS and Native, or that you have different code paths for JS and native that each use their own ppx?

jaredly commented 7 years ago

different codepaths

jchavarri commented 6 years ago

I think i'm running into the same issue. The native build uses Big_int from batteries and i'm replacing it in JS with some bindings to bn.js. The problem is I have to add these bindings to bs-dependencies in bsconfig.json, but then the native build breaks.

@jaredly if you fixed it, how did you manage to do it? i guess I can have native.json and js.json and override bsconfig.json before compiling but seems like a lot of overhead.

@bsansouci maybe ppx-flags and bs-dependencies could benefit of a similar approach than entries and subdirs? (i have no idea how hard that would be)

    "bs-dependencies": [{
      "backend": "native",
      "value": [
        "bs-bn.js"
      ],
    }],
jaredly commented 6 years ago

I just made a separate folder with a bsconfig.json in it, it worked just fine

bsansouci commented 6 years ago

@jchavarri Could you put the JS part inside a folder say src/js and add

"sources": [{
  "dir": "src,
  "subdirs": [{
    "dir": "js",
    "backend": "js"
  }]
}

So that that JS file's only used when building to JS?

jaredly commented 6 years ago

i believe it's a dependency. bsconfig doesn't support conditional 3rd-party stuff atm

jchavarri commented 6 years ago

I just made a separate folder with a bsconfig.json in it, it worked just fine

@jaredly nice, this seems to work, thanks!

Could you put the JS part inside a folder say src/js

@bsansouci As @jaredly says the problem is that this is a dependency in node_modules, out the reach of the project itself. The compilation fails when it encounters any reference to Js.

bsansouci commented 6 years ago

What about “allowed-build-kinds”?

jchavarri commented 6 years ago

oh, right! that should work in my case (bs-dependencies). I'll add it to the js lib and let you know if it works, thanks!

Would that work in the ppx-flags case? 🤔

bsansouci commented 6 years ago

You mean swap the ppx depending on whether it's JS or native? Not currently, Jared's solution is the way to go!

jchavarri commented 6 years ago

@bsansouci I tried allowed-build-kinds but doesn't seem to fix the issue. Maybe that flag works for opam dependencies only? Or I might be doing something wrong.

Supposing I have an app A and a Reason/OCaml library L, this is what i'm doing:

  1. Added "bs-dependencies": ["L"] to A's bsconfig.json
  2. Add "allowed-build-kinds": "js", to L's bsconfig.json as L is actually a Reason library with some bindings to JS.

Does that make sense?

Edit: finally found the issue thanks to @bsansouci help: I hadn't npm linked properly the Reason library, so the changes to bsconfig weren't being picked 😅