How to translate gcc CLI arguments to correponding clang arguments? #1588
Replies: 7 comments 15 replies
-
Clang, not GCC, is already the primary target of Shermes. With that said, they have compatible command line options. You are seeing errors because compiling for Wasm is not exactly the same as compiling Elf binaries. Specifically, |
Beta Was this translation helpful? Give feedback.
-
I'm thinking more of the source code is C, therefore it must be capable of cross-compilation, by some means. JavaScript to C to WASM, C++, Rust, et al. The reason is I was testing JavaScript to C, C++ code bases. ts2c, jsxx, TypeScriptCxx, compilets. Then there's a random Web site that says it's "artificial intelligence" technology converts JavaScript to C, and does. Therefore I am looking into to JavaScript engines and runtimes that could possibly achieve that, even if not within the scope of the repository. It can't be that there is no FOSS that can achieve that. That's my research interest for this project. Thanks. |
Beta Was this translation helpful? Give feedback.
-
Shermes can be used for cross compilation or to compile JavaScript to Wasm. Both work, but may require some manual steps. |
Beta Was this translation helpful? Give feedback.
-
I suspected that. Manual steps work. I have llvm-project's |
Beta Was this translation helpful? Give feedback.
-
To provide a roadmap of what I'm doing here - without using a random Web site that converts JavaScript to C - consider starting out with some JavaScript.
Using a random Web site https://products.codeporting.app/convert/ai/js-to-c/ we can get this C output
Modify the
Now we can do JavaScript <=> WASM | C | Native executable <=> JavaScript. Build a native executable with
Build WASM using WASI-SDK
Convert WASM back to JavaScript
Modify the resulting asm.js format slightly, using a minimal WASI runtime that does not define filesystem access https://gitlab.com/-/snippets/4782260
My thinking is that one of these modern JavaScript engine/runtime/compiler projects is capable of achieving true cross-compilation to/from JavaScript to C, WASM, native executable, and back to JavaScript from WASM, and possibly from C - without using an unobservable box such as
that is, without using "artificial intelligence" or "machine learning"; rather using FOSS. |
Beta Was this translation helpful? Give feedback.
-
To my knowledge, with the exception of GraalVM (which has a somewhat different focus), Static Hermes is the only production quality project that is able to compile JavaScript to native code ahead-of-time. SH is not a research or a hobby project, it is a production[1] quality compiler that can compile normal JS ES6 code to native and pass ECMAScript compliance tests (Test262). Please, keep in mind that translating JavaScript to C is not really possible, at least not in any meaningful way and certainly not at scale. JS semantics are too complex and dynamic for that. Static Hermes compiles to native, using C as a kind of high level assembly language (this is not a new technique). The generated C certainly looks nothing like the input JS. This is a shortcut, in lieu of generating LLVM IR directly, to make development easier. It is definitely possible to use Static Hermes to compile JavaScript to Wasm, since for our purposes Wasm is just a LLVM backend. In a sense, Static Hermes was designed for this. See these tweets for some interesting results: [1] While typed JS is still experimental, untyped JS is well supported. |
Beta Was this translation helpful? Give feedback.
-
Converting to discussion. |
Beta Was this translation helpful? Give feedback.
-
Problem
I successfully compile a C file to an executable using this
When I try to compile with LLVM's
clang
or WASI-SDK'sclang
I get an error for the-Wl,-rpath
optionSolution
clang
compilation corresponding togcc
compilation.Additional Context
I'm trying to compile with
clang
so I can target WASM.Beta Was this translation helpful? Give feedback.
All reactions