bsb-native icon indicating copy to clipboard operation
bsb-native copied to clipboard

Allow custom config file (not just bsconfig.json)

Open jaredly opened this issue 8 years ago • 13 comments

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).

jaredly avatar Aug 23 '17 05:08 jaredly

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

bsansouci avatar Aug 23 '17 20:08 bsansouci

ppx-flags was the one I wanted to be different

jaredly avatar Sep 10 '17 02:09 jaredly

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?

bsansouci avatar Sep 10 '17 03:09 bsansouci

different codepaths

jaredly avatar Sep 11 '17 15:09 jaredly

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"
      ],
    }],

jchavarri avatar Jan 12 '18 00:01 jchavarri

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

jaredly avatar Jan 12 '18 01:01 jaredly

@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?

bsansouci avatar Jan 12 '18 01:01 bsansouci

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

jaredly avatar Jan 12 '18 01:01 jaredly

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.

jchavarri avatar Jan 12 '18 01:01 jchavarri

What about “allowed-build-kinds”?

bsansouci avatar Jan 12 '18 09:01 bsansouci

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? 🤔

jchavarri avatar Jan 12 '18 10:01 jchavarri

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

bsansouci avatar Jan 13 '18 00:01 bsansouci

@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 😅

jchavarri avatar Jan 15 '18 14:01 jchavarri