Git Product home page Git Product logo

Comments (6)

saghul avatar saghul commented on June 12, 2024 1

Alas that's unavoidable in this case. You can use globals, or bundle all your libs in a single bundle for example.

In here the polyfill, core and run-main are 3 separate bundles each containing a bunch of stuff.

from txiki.js.

cemalgnlts avatar cemalgnlts commented on June 12, 2024 1

Understood thanks, you've been very helpful.

from txiki.js.

saghul avatar saghul commented on June 12, 2024

Then you convert the resulting polyfills.js file into polyfills.o code using qjsc.

Not quite, this generates a polyfills.c file, it's C source code, basically an array with the JS bytecode.

It's included in the build here:

src/bundles/c/core/polyfills.c

So it gets compiled with the rest of the binary.

from txiki.js.

cemalgnlts avatar cemalgnlts commented on June 12, 2024

I was thinking that the -c flag is needed to convert to C code.

-c
Only output bytecode in a C file. The default is to output an executable file.

https://bellard.org/quickjs/quickjs.html#qjsc-compiler

from txiki.js.

saghul avatar saghul commented on June 12, 2024

I was thinking that the -c flag is needed to convert to C code.

Correct, it outputs a C file. You can see it here: https://github.com/saghul/txiki.js/blob/master/src/bundles/c/core/run-main.c

from txiki.js.

cemalgnlts avatar cemalgnlts commented on June 12, 2024

When I convert a JS file to C, all its dependencies are also included in C. How did you avoid this?

I have two libraries:

  • lib-A.js
  • lib-B.js

lib-A.js needs lib-B.js.

When I compile, the lib-A.c file contains both its own code and lib-B.js, while lib-B.c contains only its own code.

It's actually normal, but it's causing problems with it.

I can avoid this like this: I create index.js file and import it into two files so I have a single module.c file that contains both lib-A.js codes and lib-B.js codes.

The minus side of this is that index.js codes that will not be used will be added and the resulting C file will be large.

from txiki.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.