-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiling JavaScript With Node.JS Source #1301
Comments
let me know which is your case. |
I'm trying to build/compile standalone JavaScript apps with only official Node.JS source/resources. I have two reasons to not use 3rd party apps. One, they typically don't work on aarch64/Android, and two, I just want to learn. |
fair points, thanks. Still trying to figure out the exact requirement:
|
/cc @nodejs/build @nodejs/core |
I don’t think tagging 86 people (core) in a help request waiting for author input is great use of core’s time. |
@benjamingr - point taken. Apologies to 86 people whose time was potentially wasted. |
@gireeshpunathil option 2, using js2c.py, and then compile that C++ code. I can't figure out how to compile it. If it's impossible, that's no big deal, I'm just doing this for fun/educational purposes. |
@benjamingr @gireeshpunathil I would argue those teams exist to be pinged. @JacobTDC the output of js2c.py is just the source of the JavaScript but in char array form. it's interpreted as a string by node.js at runtime and evaluated. it cannot run by itself. |
@devsnek those teams exist to be pinged at core issues relating to collaborators. This is a help request from a new user - important, but not important enough to encourage collaborator overcommitment IMO. I think this is a problem we have and should get better at openjs-foundation/summit#64 . Sorry for the interruption :) |
@devsnek, yes, but by including the Node.JS and V8 source, shouldn't it be possible to compile that into a standalone? |
@JacobTDC yes, that's what the final binary |
@devsnek, see EDIT above. That should clarify things. |
@JacobTDC - can you try this? g++ '-DNODE_WANT_INTERNALS=1' -I../src -I../deps/v8/include -std=gnu++1y -stdlib=libc++ -c main.o main.cc this is not backed up by any documentation, instead through following Node's build procedure for the JS files, and reducing the command line to a bare minimum that is required for most common cases. |
Have you considered building Node.js from source using |
@gireeshpunathil I'm getting a new error I haven't seen before, but all the other errors are gone:
|
I included
|
node depends on some specific files already existing ( |
Also, @gireeshpunathil, where exactly did you find that? |
@devsnek, how do I include those two files? |
my approach was simple:
the commands generated and output are precisely the ones that are required for compiling and linking the JS files.
|
@gireeshpunathil, I'm still new to C++ and compilation; can I get an English translation for that last part? XD |
sure - can you tell me how are you producing your |
I haven't passed any args except default: js2c compile
compile: config
@echo Compiling...
@g++ main.cpp '-DNODE_WANT_INTERNALS=1' -I"./node/src" -I"./node/deps/v8/include" -I"./node/deps/uv/include" -I"./node/tools/msvs/genfiles" -I"./node/deps/cares/include" -std=gnu++1y -stdlib=libc++
config:
@./tools/configure.sh $(nodeV)
js2c: config
@echo Converting JavaScript to C++...
@python2 ./node/tools/js2c.py main.cpp main.js Where My #!/bin/bash
echo "Checking for Node.js source..."
if [ ! -d "node" ]; then
echo "Node.js source not found."
if [ -n "$1" ]; then
nodeV="v${1/#v}"
echo "Getting Node.js $nodeV"
nodeTab=$(wget "https://nodejs.org/dist/index.tab" -qO -)
if [ -z "$(echo $nodeTab|grep "$nodeV\s")" ]; then
echo "Node.js version \"$nodeV\" does not exist!"
exit 1
fi
nodeUrl="$nodeV/node-$nodeV.tar.gz"
else
echo "No version specified, getting latest."
nodeUrl="node-latest.tar.gz"
fi
tmpDir=$(mktemp -d "./tmp-XXXXXX")
trap "{ rm -rf $tmpDir; }" EXIT
echo "Downloading..."
wget "https://nodejs.org/dist/$nodeUrl" --show-progress --progress=bar -qO -|tar xpz -C $tmpDir
mv $tmpDir/* node
rm -rf $tmpDir
else
echo "Node.js source found."
fi |
@JacobTDC - the missing symbol error ( However, I fear you may get new errors based on additional symbols being missed. So 2 options:
I did not try this myself (will try), but from the documentation this looks like the right path. |
@gireeshpunathil it worked (though I did have to change |
Actually, I'm getting a lot of |
@JacobTDC - good to know you are progressing.
No, I am unable to guess. Why? memory? lack of ABI support? or something else? But nevertheless, that question hints at your intention as to convert JS code into C++ and run them standalone executable? as opposed to having a Node.js runtime? That will be tough, if not impossible:
|
@gireeshpunathil, I waited for an hour, and still didn't fully build Node. My phone doesn't have enough processing power to build ALL of Node in a practical amount of time. |
I used option 1, BTW. |
@JacobTDC - thanks
agreed, that is what we are attempting. but not having the infrastructure to do that is where we are.
|
@gireeshpunathil, using |
you need to link it with node.o (+ all other object files from node and v8) to make an executable. If you do |
@gireeshpunathil Where is |
Wait, NVM, just realized. Your response just clicked for me... |
I assume node.o is the Node.js executable? |
At one point I assumed that you were trying to build a virtual machine by hand, but from further interactions including the last one, I realized that you are experimenting and trying to learn. That is absolutely fine, but the direction you are wanting to take is neither supported, recommended nor tested. To add to that, you seem to be wanting to have this on a platform that inhibit these experiments. I recommend that
hope this helps. |
Believe it or not, my PHONE has more processing power than my computer (XD), and I just like to experiment on it. However, @gireeshpunathil, I will try using a Linux VM. Maybe that will work better. |
@JacobTDC - wonderful, thanks. Let me know if you have got all the info that you wanted. |
@JacobTDC - how is it going? are we all well and close this? |
@gireeshpunathil I'm closing the issue now. Sorry, I forgot to close it... XD |
I know I just closed this, but for anyone interested, I found patches that fix Node for android here: https://github.com/termux/termux-packages/tree/master/packages/nodejs |
How would I go about compiling Node.JS code using the source files and GCC/G++? I've figured out how to use
tools/js2c.py
to get C/C++, but how do I include all relevant header files to GCC without doing it manually?Makefile
:tools/configure.sh
:The text was updated successfully, but these errors were encountered: