-
Notifications
You must be signed in to change notification settings - Fork 6
Extract the io_file POSIX API into a separate package
#272
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
61974a3
Extract the POSIX API into a separate package
brianquinlan 1ab43b2
Fixes
brianquinlan ba3c7a6
Update io_file.yml
brianquinlan 9b7aa90
More cleanup
brianquinlan c2478fb
f
brianquinlan 2dbe248
Update build.dart
brianquinlan ad21527
Update unix_api.yml
brianquinlan 4030682
Updates
brianquinlan 3ce6ab2
Fix version
brianquinlan 1f14c7c
Review feedback
brianquinlan b402a97
Update pubspec.yaml
brianquinlan 7fd1efa
Update pubspec.yaml
brianquinlan 5c8b0d2
Update pubspec.yaml
brianquinlan f273308
Update pubspec.yaml
brianquinlan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: package:unix_api | ||
|
|
||
| permissions: read-all | ||
|
|
||
| on: | ||
| # Run CI on pushes to the main branch, and on PRs against main. | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - '.github/workflows/unix_api.yml' | ||
| - 'pkgs/unix_api/**' | ||
| pull_request: | ||
| branches: [ main ] | ||
| paths: | ||
| - '.github/workflows/unix_api.yml' | ||
| - 'pkgs/unix_api/**' | ||
| schedule: | ||
| - cron: '0 0 * * 0' # weekly | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: pkgs/unix_api | ||
|
|
||
| jobs: | ||
| analyze_and_format: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
| - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c | ||
| with: | ||
| sdk: dev | ||
| - run: dart pub get | ||
| - run: dart analyze --fatal-infos | ||
| - run: dart format --output=none --set-exit-if-changed . | ||
|
|
||
| check-generation: | ||
| # Verify that the generated code is up-to-date. Every platform/arch should | ||
| # generate the same API bindings. | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [macos-latest, ubuntu-latest, ubuntu-24.04-arm] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
| - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c | ||
| with: | ||
| sdk: dev | ||
| - run: dart pub get | ||
| - run: dart --enable-experiment=native-assets run tool/generate.dart | ||
| - run: git diff --exit-code | ||
|
|
||
| desktop-vm-test: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| sdk: [dev] | ||
| os: [macos-latest, ubuntu-latest, ubuntu-24.04-arm] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
| - uses: dart-lang/setup-dart@e51d8e571e22473a2ddebf0ef8a2123f0ab2c02c | ||
| with: | ||
| sdk: ${{ matrix.sdk }} | ||
| - run: dart --enable-experiment=native-assets test --reporter=failures-only --test-randomize-ordering-seed=random --platform vm |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,4 @@ dev_dependencies: | |
| url: https://github.com/canonical/stdlibc.dart.git | ||
| test: ^1.24.0 | ||
| uuid: ^4.5.1 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # https://dart.dev/guides/libraries/private-files | ||
| # Created by `dart pub` | ||
| .dart_tool/ | ||
|
|
||
| # Avoid committing pubspec.lock for library packages; see | ||
| # https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
| pubspec.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ## 0.1.0-wip | ||
|
|
||
| - Initial version. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| This package provides **experimental** bindings to POSIX APIs e.g. `open`, | ||
| `close`. | ||
|
|
||
| ## Why have another POSIX API implementation for Dart? | ||
brianquinlan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Thare are two existing packages that provide POSIX API bindings for Dart: | ||
| 1. [`package:posix`](https://pub.dev/packages/posix) | ||
| 2. [`package:stdlibc`](https://pub.dev/packages/stdlibc) | ||
|
|
||
| `package:unix_api` requires a native tool chain and has a small amount of | ||
| native code that cannot be tree shaken away. In exchange, it works on all | ||
| POSIX platforms that Dart supports. | ||
|
|
||
| | Package | Required Tools | Supported Platforms | Fixed Disk Usage | | ||
| | :--- | :-------------- | :------------------------------------ | :-------------- | | ||
| | `posix` | Dart | iOS (arm64), Linux (x64), macOS (arm64) | 0 KiB | | ||
| | `stdlibc` | Dart | iOS (arm64), Linux (x64), macOS (arm64) | 0 KiB | | ||
| | `unix_api` | Dart, C compiler | Android (x64, arm32, arm64), iOS (arm64), Linux (x64, arm64), macOS (x64, arm64) | ~60 KiB | | ||
|
|
||
| ## Design | ||
|
|
||
| The POSIX API is a defined in terms of source, not object compatibility. | ||
|
|
||
| For example, glibc defines `stat` as: | ||
|
|
||
| `#define stat(fname, buf) __xstat (_STAT_VER, fname, buf)` | ||
|
|
||
| So running `ffigen` on `sys/stat.h` will not produce an entry for `stat`. | ||
|
|
||
| libc may also reorder `struct` fields across architectures, add extra | ||
| fields, etc. For example, the glibc definition of `struct stat` starts | ||
| with: | ||
|
|
||
| ```c | ||
| struct stat | ||
| { | ||
| __dev_t st_dev; /* Device. */ | ||
| #ifndef __x86_64__ | ||
| unsigned short int __pad1; | ||
| #endif | ||
| #if defined __x86_64__ || !defined __USE_FILE_OFFSET64 | ||
| __ino_t st_ino; /* File serial number. */ | ||
| #else | ||
| ``` | ||
|
|
||
|
|
||
| `package:unix_api` works around this problem by defining a native (C) function | ||
| for every POSIX function. The native function just calls the corresponding | ||
| POSIX function. For example: | ||
|
|
||
| ```c | ||
| int libc_shim_rename(const char *old, const char *newy) { | ||
| return rename(old, newy); | ||
| } | ||
| ``` | ||
|
|
||
| This allows the platforms C compiler to deal with macro expansions, | ||
| platform-specific struct layout, etc. | ||
|
|
||
| Then `package:unix_api` uses `package:ffigen` to provide Dart bindings to | ||
| these functions. | ||
|
|
||
|
|
||
| ## Status: Experimental | ||
|
|
||
| **NOTE**: This package is currently experimental and published under the | ||
| [labs.dart.dev](https://dart.dev/dart-team-packages) pub publisher in order to | ||
| solicit feedback. | ||
|
|
||
| For packages in the labs.dart.dev publisher we generally plan to either graduate | ||
| the package into a supported publisher (dart.dev, tools.dart.dev) after a period | ||
| of feedback and iteration, or discontinue the package. These packages have a | ||
| much higher expected rate of API and breaking changes. | ||
|
|
||
| Your feedback is valuable and will help us evolve this package. For general | ||
| feedback, suggestions, and comments, please file an issue in the | ||
| [bug tracker](https://github.com/dart-lang/labs/issues). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:unix_api/unix_api.dart'; | ||
brianquinlan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void main() { | ||
| print('I am ${getpid()} and my parent is ${getppid()}'); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'd try using something like
^0.1.0here, and add a dependency_overrides section further down: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.
Done.
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 changed to back because changing this also trickles into the mobile_test subproject and it seemed better to contain the path reference here. WDYT?
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.
Well, it's not normally how we'd try and reference a package - it'll mean that
io_filewon't be useable outside this repo. I'm not sure what the issue is w/ the subproject.Feel free to use your best judgement here though; we're not trying to ship this currently. If you do use a relative reference into this repo, you might leave a comment that this isn't our normal practice.