-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
Create asbuild tool to fix passing asc parameters on the npm run command line #975
Conversation
Currently, the recommended way to specify such options is to edit the |
It is an option. This PR was just an offer for a simpler path for applying parameters temporarily or experimenting with them. I also admit that I am not very familiar with npm-based packages, and it was an attempt to make the build commands behave similar to those I was familiar with. I say simpler, because this was not a trivial thing for me to figure out. There is much weirdness in
One parameter (such as All that said: if editing I just want to save others the exercise I went through. |
From a quick test is appears that if there is "scripts": {
"asbuild:untouched": "asc ...",
"asbuild:optimized": "asc...",
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized"
} with
one will get
but with
one will get
which is a parameter to
yields
which does what one wants, but only for the second command. Wondering if we can improve the |
Ah, I see. It was the first command I was looking at, and thought it did nothing. In that case, I will poke around a little more and try to fix that. I did figure out how the scripts were passed to bash (as basically standard input, which means certain things about the argument variables and quoting), but that was the one mystery. |
With that piece of the puzzle, I think I did it. Ready for review! |
bin/asinit
Outdated
@@ -210,7 +210,7 @@ function ensurePackageJson() { | |||
const entryPath = path.relative(projectDir, entryFile).replace(/\\/g, "/"); | |||
const buildUntouched = "asc " + entryPath + " -b build/untouched.wasm -t build/untouched.wat --sourceMap --validate --debug"; | |||
const buildOptimized = "asc " + entryPath + " -b build/optimized.wasm -t build/optimized.wat --sourceMap --validate --optimize"; | |||
const buildAll = "npm run asbuild:untouched && npm run asbuild:optimized"; | |||
const buildAll = "function build_all() { npm run asbuild:untouched -- $* && npm run asbuild:optimized -- $*; }; build_all"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it'll break on Windows :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, Windows? I thought this required a POSIX shell (i.e. Cygwin or WSL). Even the previous version used &&
which I didn't think was understood by traditional cmd.exe
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, there's not much bash and cmd have in common, but &&
works :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, would you accept executing a new .js file in node? It seems like overkill, but I don't know of any other way to support Windows...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it could be implement via concurrently
package and some extra script like here: https://github.com/kimmobrunfeldt/concurrently/issues/33#issuecomment-433084589
But it's extra dependency and isn't it too overcomplicated? Hmm
Since I currently have no way to test Windows myself, I though it wise to write a separate PR (to land first) which added a Windows builder to GitHub Actions. It turned out to be easy to add, but the new builder hit a rather strange error in the nvm version from @dcodeIO 's repo (note this log is from a PR against my own fork): https://github.com/jhwgh1968/assemblyscript/pull/2/checks?check_run_id=327529556 It seems something strange happened with the Any ideas? |
nvm has no Windows support, unfortunately. The reason for using a custom action there is that we need aliases for "latest node stable" (node) and "latest node lts" (lts/*), which other solutions that would work on Windows do not yet support. That's a bit of a mess currently. Perhaps we can make our own action that replaces nvm and has aliases? Most notable differences on Windows are that env variables take the form |
I guess this could be normalize via cross-env |
Seen this, yeah. But unfortunate that we'd need a dependency just for that. |
I also found a version of nvm that claims to support windows: It is pretty old, and there is a patch that seems like a good idea to apply: But it might work. Is that a good way forward, @dcodeIO? EDIT: This one is recommended by the README and seems newer: |
This more maintainable https://github.com/coreybutler/nvm-windows but it require Go 😂 |
It requires Go to build from source, but the project has binary releases. Since this is only being used on a Windows builder, I was thinking about just downloading and unzipping it in the GitHub Action, without any changes to project dependencies. |
yes, hope prebuild release works on windows in ci |
Success! Windows CI PR: #984 |
With the Windows CI PR in place, I wrote a first draft of the approach I suggested earlier. Thinking about @MaxGraey's concerns, I did not add any dependencies. Javascript is not a language I am very good with, so I expect it will require clean up and more testing. I am most interested in feedback about whether this approach is acceptable. |
Being somewhat hesitant on adding a file just for this to the scaffold. Perhaps a cleaner strategy could be to provide an
would replace
Ultimately, one can choose either of these ofc, with asbuild supporting even more stuff we add over time? Additional stuff we might want to add in follow-ups might be
Another nice side-effect of this is that we don't have to come up with our own configuration options format stuffed into |
I've been working on this, but it's not quite ready yet. See if my new approach is better:
Is that more what you were thinking, @dcodeIO? |
p. 2. make all things much complicated. Like if we want optimize build we should use "--optimize" and "--optimized" at the same time which looks verbose. In other hand if we want untouched with |
Yes, that is a good point. I was originally trying to make the smallest change possible, rather than thinking bigger picture. In that case, how about I take a page from the Rust language's book, and organize the options into "profiles"? That is, rather than setting all the settings This is more or less what the current scripts do with "untouched" versus "optimized". This tool would just make that more formal, and allow it to expand in a more natural way over time. Here is the output from my current WIP command (which uses the yargs parser) to illustrate what I mean:
I copied the profile names from Rust's build system, cargo. (Since that is largely modeled on npm, I thought that was fair. 😄 ) Notice they are words describing the end product -- "a build for release" -- rather than words describing its contents -- "a build that is optimized", "a build with debug symbols". I think this addresses your point, @MaxGraey. The only required argument is Only commands in Right now, I am following current file names: "untouched" is the default name for the debug profile, and "optimized" is the default name for the release profile. But I can easily change that if you want. How does that sound? |
you should sync with master and make |
Thanks, @MaxGraey. |
Now that my CI issue is fixed, is this more like what you were expecting, @dcodeIO? I will probably finish it up this week if so. Also, I did have to add one dependency to avoid a lot of frustration. |
I like the idea of having
So perhaps that'd be good profiles to begin with? These could live in Now I'm always cautious when dependencies are added, mostly because it's hard to keep track of dependencies of dependencies which can become a security nightmare or package bloat. Like, we have just Apart from that I suggest to keep option names somewhat close to those of asc, here |
Thanks for the feedback, @dcodeIO. Based on that, I'll make some fixes, and the next commit should be ready for merge. |
Alright, @dcodeIO, I think I've got it pretty much done. I think I have taken all your design suggestions, and avoided adding any dependencies. Ready for review! |
Causes projects generated by
asinit
to allow passing arguments to theasc
command line when doing annpm run asbuild
via an environment variable.This is to make passing things like
--use abort=
and--noAssert
easier.I tried using the standard npm argument parsing at first, but it behaved very strangely.