-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Connect executables
with targets
#591
Comments
I really like this idea of being able to list out
This portion I dislike, but maybe I'm not seeing the benefit - why would I want to wait for a tool to build the first time I invoke it, instead of when I run I can't speak for others, but I only include executables / tools that I actively use in my |
@Vici37 IIUC The reason is to reduce the |
Use cases differ. I would argue that I might not need all these tools if I just want to checkout the code of your shard, or maybe to build it and run tests?
And I'm not suggesting that lazy building should be the only option. If you want to have all executables build on |
That's fair. Reading your reasons for wanting to pull and build a given shard here, it does look like there's existing I'm not opposed to creating a new sub-sub command to handle this phase (i.e. |
I've built a proof of concept for this into my Interro shard in this commit. I updated one of my apps to use that branch and this is what happens when I run my bin/setup script which, among other things, calls
Note that when it ran And this is repeatable — I’m running |
The current solution (calling What about asking users to write a 3 lines script that they can then customize, or even embed right into their own executable (as a subcommand for example)? require "pg"
require "my_migration/cli"
MyMigration::CLI.call(ARGV, ENV["DATABASE_URL"]) |
I didn't call it a solution. I called it a proof of concept. It is not intended to cover every use case as written. A proper solution using this idea would include a pattern that already has precedent in several parts of the Crystal stdlib — we can simply generate code based on which platform is in use. If a POSIX system doesn't have
This helps avoid compiling There are times when writing a CLI can't be avoided (background job processors need the code from your app's background job handlers, for example), but if I have to do it for every CLI I use, I'd be annoyed as hell. I'm autistic and putting that many speed bumps in front of me would make me lose interest in this ecosystem entirely. I use the CLIs I use for the same reason I want them compiled when I install/update their shards: because automating manual processes is frequently a good thing. The shell script shim will overwrite the existing binary any time the shard is updated, which will then recompile the CLI automatically. |
It occurred to me that, without this context, the magnitude of my objection might seem a bit excessive: I use Crystal primarily for microservices. These services aren't tiny single-function deployments, but I'm not dealing with a monolith, either, due to compilation times. You may think it's not a big deal to write a single CLI and I can sympathize with that perspective (while I don't agree with it, I do understand it), but with 4 shards providing CLIs (protobuf, grpc, interro, and wax) across 13 services, that's 52 CLIs to write. It also means the extraction of new services comes with the overhead of writing 4 more shard CLIs on top of the entrypoints for the service itself. And while there might be some commonalities that could be used across all these services, I'd still have to rearchitect my services' entrypoints because a handful of people don't want to compile That's why I'm trying to accommodate Johannes's idea of lazily compiled binaries. It took me a while to come around to it but, after trying it out, it seems like a great compromise. |
Thanks, this is what we want: use cases! I'm not saying the following are good ideas. I'm trying to think out of the box: how would we do without postinstall and executables? What about a monorepo or docker container or nix environment, so you'd only write it once per shard and use everywhere? You'd only build (or download) 4 executables instead of 13 times the same 4 executables. Adding a service would immediately use that environment, no need to install all these executables again. Doesn't For example we install Crystal and its stdlib once, either globally or through asdf, docker or nix. We could install and build it for every project 🤷
That sounds horrible for Shards to implement and maintain 😨 |
Thank you @jgaskins for sharing your use case. I know what I'm about to ask is weird, but bear with me for a minute: What if shards never implemented I know is hard to imagine that scenario since
What about the other shards that are part of your projects, and the possible CLI they provide? How about these shards depending on each other that also may or may not need the CLI provided for them to work? I'm honestly interested to hear this, as we are all talking about removing a functionality and the anxiety and fear that generates, without seeing the possibilities of that being accomplished differently. Thank you for your patience, openness and candor on your comments. |
This is what I was getting at with "I'd still have to rearchitect my services' entrypoints…". The shard developers would ideally still document how to include these things in your apps, but (a) I don't imagine that practice would be universal[1], and (b) the ones that do will still end up having to put effort into documentation for that, which can become out of date without the maintainer noticing. That is highly unlikely with And it still puts responsibility onto the developers of the apps. I would have to come up with some kind of solution for this that I currently do not have to come up with. This is a net negative for me.
The main reason it's implemented as a shard is that the code it generates depends on I've also been considering implementing a plugin architecture for it that works kinda like
Is it meaningfully different from how Crystal provides all of these LibC backends and scans multiple locations for TZ databases? [1]When there is a knowledge imbalance about a manual process, the people that have intimate knowledge about the thing will assume others do, too. This happens a lot: engineers talking with non-engineers about how a feature works, engineers working on infrastructure talking to engineers who work on application code, etc. In this case, the maintainers would know about the updated API, but others would not. |
Could you clarify what you mean with "CLIs to write"?
|
Julien's suggestion here:
The idea doesn't scale for microservice architectures.
Sure, in theory. I could extract other parts of In practice, this puts yet another burden on the app developer. If It creates a 1:N relationship between the code generator and the number of versions of the dependencies that
|
Funny you mention this. The
I deploy containers and the CLIs only ever have to build when the shards change (new shards added, one or more updated, etc). My apps have |
shard.yml
allows defining executables that are supposed to be installed in the main project'sbin/
folder, and it allows defining build targets. But they are currently not related.If executables need to be built, the only way to do that is run a build command in
postinstall
. Ideally, that's justshards build
.I think it would be a good opportunity to automate that by hooking up
executables
with the availabletargets
information.Operation would be quite simple: When shards cannot find a file for a declared executable, but there is a
target
definition of the same name, it runsshards build $executable_name
. Then the executable file should exist.This works without disrupting existing workflows where the executable is already available in the source or built by a postinstall hook because existing files would be preferred.
An immediate result is simplification of the
shard.yml
, with the additional benefit of turning imperative instructions into declarations (which helps portability).So the above
shard.yml
could be shortened to this:No need to define
shards build
(or the equivalent usingmake
or whatever) inpostinstall
.This probably won't work for all shards, because some have more complex builds. But I figure it should be good for the vast majority of typical development tools.
As a further enhancement, instead of building directly upon installation, the executable could actually be a shim which invokes the build command on demand. This avoids waiting for executables to build when running
shards install
and only builds them if they are actually used. That causes some delay when used the first time, but that should be acceptable: If you want to use it, you have to wait for the build anyway at some point. But if you don't use it, there's no need to build it!This proposal is based on some ideas previously mentioned in https://forum.crystal-lang.org/t/shards-postinstall-considered-harmful/3910/14?u=straight-shoota
The text was updated successfully, but these errors were encountered: