-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
🪝 [breaking change] Reserve top-level hook/
directory 🪝
#54334
Comments
Ready for another round of bike shedding. @mit-mit @mraleph @mkustermann @mosuem @devoncarew @HosseinYousefi @jonasfj and who else wants to chime in. |
Another solution would be to introduce a top-level directory called |
Having a directory would fit with a possibility of having pub resolve dependencies differently in a directory:
Flutter already has an |
Yes!
The place for assets is not hardcoded in Flutter, but it's true that usually people use the name |
I'd also prefer to not such scripts in the root directory.
And with good reason, it's because they shouldn't be. That's prime real-estate that should belong to the author. Or for the author to ensure it's kept clean, if they don't want clutter. The Probably not a Maybe Do we expect more scripts to be added in the future, or is this going to be about FFI native assets forever. If so, the script names should be less generic. Maybe Is "asset" the best name, if that's already what people are using for their icons? (The name has always confused me when used about native resources, probably because I associate it strongly with web assets.) Could it be |
@mosuem wants to use the (to be built) Whatever comes out of That being said, maybe we have a need for some kind of pre-defined script in the Dart/Flutter eco system that is not related to bundling assets (be it code or data), but is a predefined script name. So in that case even "asset" is not the right name either. Currently "asset" is the right name, but it might not be in the future.
I think I like the last one best, but it's long. Python and Node use the term "hooks". Som we could reserve the folder |
Will the scripts need to be |
We require these scripts to be dart scripts. We can use the "current" Dart executable to run these scripts from where we want to run them. We could require the dart scripts to be marked executable and having dart on the path, but that means we cannot rely on that Dart executable being the same one as "the host". So I think that would be a bad idea.
Be my guest. 😅 |
Do current build stack and web compilers migrate to this? I love to see something like zig build system. Typed. No |
Web frameworks should not use a Dart command-line and Flutter apps consume the output of
If we standardize to a build system around Dart, it would be Bazel most likely. In which case |
@devoncarew mentioned that A similar concept could be applied here; having a top-level
This could be defined in the pubspec as scripts:
pre-kernel-compilation:
build
post-kernel-compilation:
link
pre-testing:
test_setup with a top-level These features would help the ecosystem, even if they make the process slightly more magic. If a repository requires extra steps to be done before testing, running |
I love the idea of having a place to hook in to for making sure all generated code is indeed regenerated before If we would go for "script", then the script/ directory as suggested by Lasse makes sense. (Together with a A package layout would then be:
|
A few notes:
Honestly, I don't know that it would be unfair to put a Probably we should be careful what hooks we introduce into the Dart SDK. But I see |
@dcharkes there has been a lot of discussion around this breaking change, are we ready to push it up the approval queue? |
Based on the discussion in this issue and related issues, the two most probable options are:
I'm not fully bought in to "script", but I believe it's the best option out of all the suggestions made in this issue and related issues. If we want to go for option 1, then I'll rephrase the issue reserve the top level script folder. @mit-mit @mkustermann @mraleph @devoncarew @HosseinYousefi @mosuem @jonasfj @lrhn Any concerns? If not I think we should just chose it and move forward. |
At the risk of further bikeshedding on the name, perhaps reserving build and link script names in a
That wouldn't pollute the top-level directory w/ single scripts, and would be forwards compatible w/ any declarative workflow scripts defined in the pubspec file, if we choose to explore that (i.e., this comment). |
The more I think about it, the less I like If the directory is intended to hold multiple files, which may include data files, not just scripts, what is the concept that binds these files together, and which can be used as a filter when deciding whether a file good in there or not? "Script" fails to filter, any script that I wrote would fit that name. If we're not filtering anyway, I'd just use Devon suggests "workflow". Not sure it's precise enough, it doesn't say which workflow. I can think of many. Same issue for Maybe So define, precisely, what the directory is intended to be used for. Find a single concept which clearly and precisely covers that (what is it, what is it not). Use that concept as name. Then consider whether it can be a subdirectory of |
One issue with making it a subdirectory is the discoverability. If we're going to run package author code automatically on users machines, (on pub get, on build, on ...) I think that that should be easy to spot.
So, Rust goes for a single concept, and it only has one file. NPM and Python go for multiple concepts and give the thing a generic name such as 'hook' or 'script'. Because we've got more use cases than just |
I worry that the name So consider something less attractive, like (We should still show warnings of someone adds an unrecognized script in there, and day that if the recognized scripts need helper scripts, put those under |
I think |
Or rather |
My bad. That folder are inside the |
I usually see the Git hooks directory to be |
@HosseinYousefi Yeah you are right. I got quite confused there :) |
|
We did consider this (#54111) (for example nodejs does this with a
You can't and you shouldn't. The package you're consuming does not work without executing these scripts. See #50565 and flutter/flutter#129757.
An error message when trying to do
Yes. You're going to build C libraries (process invocation to a C compiler). Or download files from a CDN. |
This seems like it will cause problems for platforms/build environments the author didn't consider properly. For example, a significant number of projects we support build using a Bazel -like build system. We have users who want to build and run applications in environments with musl instead of glibc. We have users who build using MSVC, gcc, clang, apple-clang. We have a number of architectures to support. With regard to the original suggestion, I'm not "opposed enough" to |
Checking in again on this breaking change request @dcharkes |
It should be
cc @christopherfujino Any concerns from your side? |
@dcharkes what is your recommendation for people using a another build system (like bazel)? |
People using custom build systems will naturally have to do custom stuff, there is no silver bullet. Similar to how Pub packages don't automatically come with That being said this discussion certainly does not belong to this particular breaking change. If there are some specific concerns @reidbaker @dnfield - I encourage you to suggest to fork a separate issue with details or start a mail thread. |
SGTM |
I did a quick search and this shouldn't impact internal code. SGTM. |
Does the error message explain the magical nature of these files? That would mitigate the breakiness significantly. Anyway, I still have no objection. |
lgtm |
Thanks everyone for your input! 🙏 I'll start working on:
And close this issue once it's done. |
For context: * dart-lang/sdk#54334
Specify the `hook/` directory in the package layout. * dart-lang/sdk#54334 --------- Co-authored-by: Jonas Finnemann Jensen <[email protected]> Co-authored-by: Parker Lougheed <[email protected]>
Specify the `hook/` directory in the package layout. * dart-lang/sdk#54334 --------- Co-authored-by: Jonas Finnemann Jensen <[email protected]> Co-authored-by: Parker Lougheed <[email protected]>
This change is now part of Dart and Flutter on the main branch. |
`hook/` is a reserved directory. #54334 And the two hooks currently in existence require to be invoked with the same dependencies as the root package. Hence the dependencies of the hooks should be normal dependencies and not dev dependencies. Bug: dart-lang/native#160 Change-Id: I7cf48659bd240c2e46b5bdede2a336763301b8c5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383301 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Daco Harkes <[email protected]> Reviewed-by: Hossein Yousefi <[email protected]>
Change intent
(edit: Updated 2024-01-24 to reflect use of the
hook/
toplevel directory.)A package toplevel
hook/
directory will be reserved for scripts run by the Dart and Flutter SDK at specific lifecycle events with a specific commandline API.Examples:
hook/build.dart
will be run before kernel compilation of Dart packages.hook/link.dart
will be run after kernel compilation of Dart packages, before making an application bundle.If these scripts exist, they will be invoked by the Dart and Flutter build systems.
If these scripts exist, they must implement the commandline API.
For more context:
For more
Justification
Other languages standardize on a top level build script that builds code in other languages.
Most notably Rust defines a top level
build.rs
in packages to build native non-Rust code.Reasoning for using
hook/build.dart
andhook/link.dart
in Dart.lib/
andbin/
directory. But build scripts should not be part of the programmatic or CLI API of a package.tool/
. But build scripts should be run from the context outside that package itself.build/
directory is already reserved in Flutter. So nesting the build script inside thebuild/
directory doesn't work.Alternatives considered
build.dart
andlink.dart
. Rejected because we might want more scripts.build_assets.dart
andlink_assets.dart
. Rejected because of longer names.build.dart
path configurable #54111Impact
Anyone using a top level
hook/
directory will need to migrate to a different file name.We are aware of one use:
Mitigation
Migrate existing uses of
hook/
totool/
, which is probably what those scripts are.Action items after accepting proposal:
hook/
build.dart
tohook/build.dart
native#823hook/build.dart
instead ofbuild.dart
flutter/flutter#138727The text was updated successfully, but these errors were encountered: