Skip to content
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

Implement for Haiku #66

Merged
merged 16 commits into from Oct 8, 2022
Merged

Implement for Haiku #66

merged 16 commits into from Oct 8, 2022

Conversation

Kijewski
Copy link
Collaborator

@Kijewski Kijewski commented Sep 28, 2022

Tested on Haiku R1/beta3.

The stress-test takes 1m43s. That's quite terrible.

@Kijewski Kijewski marked this pull request as draft September 28, 2022 11:30
@Kijewski Kijewski added the Unsafe-Proposed `unsafe` code is added or changed label Sep 28, 2022
@Kijewski Kijewski force-pushed the pr-haiku branch 2 times, most recently from 2260993 to c0b8d16 Compare September 28, 2022 16:04
Tested on Haiku R1/beta3.
@Kijewski Kijewski marked this pull request as ready for review September 28, 2022 21:18
@Kijewski Kijewski changed the title WIP: haiku Implement for Haiku Sep 28, 2022
@lopopolo
Copy link
Collaborator

Is binding to the haiku C++ API with a small native extension compiled by cc in build.rs an option here? This looks like it would be a lot simpler and less error prone since it is one API call.

https://www.haiku-os.org/docs/api/classBTimeZone.html

@Kijewski
Copy link
Collaborator Author

Sure! Do you have experience how to work with cxx?

BLocaleRoster::GetDefaultTimeZone() + BTimeZone::ID() + BString::CopyInto(&buf, 0, i32::MAX) should do exactly what we need.

@lopopolo
Copy link
Collaborator

lopopolo commented Sep 28, 2022

I don't have experience with ccx to call this directly in Rust, but a tiny .cpp file with a C ABI export and one header can be made pretty usable with the cc crate and bindgen (or even a hand rolled single extern declaration) in a build.rs script.

I'd probably prefer to not add a dep on bindgen because it is fairly heavy but it also has a CLI which we could use to generate bindings from a C++ header and check in, similar to the approach you use for the tzdb perfect hash function.

@Kijewski
Copy link
Collaborator Author

It works. The stress-test now executes in 19 seconds.

Well, at least on an x86_64 system it works. But even if it only works for 64bit systems, I guess that's good enough.

@lopopolo
Copy link
Collaborator

This is looking great!

If you'd like to add clang-format to CI, we can use: https://github.com/artichoke/clang-format. I use it in Artichoke for C code. I recently added C++ support to the file scanner.

I tried it out with a simple .clang-format config and came up with this:

commit 20fa465a054534b98955a721ad5ba7dad03e851a (HEAD -> pr-haiku)
Author: Ryan Lopopolo <rjl@hyperbo.la>
Date:   Wed Sep 28 19:41:25 2022 -0700

    Add clang-format config

diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..444c17f
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,9 @@
+---
+BasedOnStyle: Google
+IndentWidth: 4
+ColumnLimit: 100
+---
+Language: Cpp
+SortIncludes: false
+TabWidth: 4
+UseTab: Never
diff --git a/include/impl_haiku.h b/include/impl_haiku.h
index cd50fe8..2d9c362 100644
--- a/include/impl_haiku.h
+++ b/include/impl_haiku.h
@@ -5,5 +5,5 @@
 #include <cstddef>

 namespace tz_haiku {
-    size_t get_tz(uint8_t *buf, size_t buf_len);
+size_t get_tz(uint8_t *buf, size_t buf_len);
 }

A GitHub Actions workflow to check this in CI looks like:

  c:
    name: Lint and format C
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: Setup Node.js runtime
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install npm
        run: npm i -f -g npm@8.16.0

      - name: Lint and check formatting with clang-format
        run: npx github:artichoke/clang-format --check

Copy link
Collaborator

@lopopolo lopopolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a suggested change to make the Rust side of things a bit easier to read and I was hoping we could add some comments in a couple of places on the C++ side of things.

Thanks for digging into cxx and the Haiku C++ docs. I like this a lot better than the initial pass at this PR.

src/impl_haiku.cc Outdated Show resolved Hide resolved
src/impl_haiku.cc Outdated Show resolved Hide resolved
src/impl_haiku.cc Outdated Show resolved Hide resolved
include/impl_haiku.h Outdated Show resolved Hide resolved
src/tz_haiku.rs Outdated Show resolved Hide resolved
src/tz_haiku.rs Outdated Show resolved Hide resolved
src/tz_haiku.rs Outdated Show resolved Hide resolved
@Kijewski
Copy link
Collaborator Author

I don't understand how this change could break the wasm implementation?? https://github.com/strawlab/iana-time-zone/actions/runs/3148078221/jobs/5118236934

Kijewski and others added 7 commits September 29, 2022 16:14
Co-authored-by: Ryan Lopopolo <rjl@hyperbo.la>
This fixes the compilation errors with -Zminimal-versions, but I don't know why.
I couldn't find anything in the wasm-bindgen changelogs, but I found these:

- libp2p/rust-libp2p#2020
- libp2p/rust-libp2p#2023
@lopopolo
Copy link
Collaborator

I'm not sure either, but I bumped the minimum version of js-sys which seems to have fixed it for me locally

Cargo.toml Show resolved Hide resolved
src/impl_haiku.cc Outdated Show resolved Hide resolved
src/impl_haiku.cc Outdated Show resolved Hide resolved
@lopopolo
Copy link
Collaborator

This is looking good! One more question on the C++ side.

@lopopolo
Copy link
Collaborator

@astraw this looks good to me. Do you want to take a quick look before we start the 7 day clock on this unsafe-proposed PR?

@astraw
Copy link
Member

astraw commented Sep 30, 2022

Thanks.

However, I think a build.rs on all platforms is a heavy price to pay to support a single platform, namely haiku. Can we move the haiku specific build.rs and cxx stuff to a separate crate (in the same git repo) so that build.rs is isolated to that platform?

@Kijewski
Copy link
Collaborator Author

build.rs's main function is empty for other OSes. cxx is only included for that one OS, because everything is wrapped in

    #[cfg(target_os = "haiku")]
    let _: () = {
        ....
    }

I don't think that having an empty build script would make a noticeably difference.

@astraw
Copy link
Member

astraw commented Sep 30, 2022

The concern is that the build script must be executed (not what it executes per se). I'm not so much worried about execution time etc but rather about cross compilation or using other toolchains etc.

@Kijewski
Copy link
Collaborator Author

Cross compilation is not affected, because the build script is always only executed on the host. At least I don't see how it could be affected right now.

E.g. if your build.rs to read /etc/hostname that will work on a linux host even when cross compiling to windows. But it will fail on a windows host, even when cross compiling to linux.

@astraw
Copy link
Member

astraw commented Sep 30, 2022

Yes, a build.rs file triggers building and execution of code on the host during cross compilation. My point is that this brings complexity for no gain on all platforms except Haiku. To me, the alternative is relatively painless and only paid by people building for Haiku.

@Kijewski
Copy link
Collaborator Author

Yeah, also this way users of other OS don't need to wonder why iana-time-zone executes a build script all of a sudden. I split off the code into its own crate.

Copy link
Member

@astraw astraw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the one trivial change, this looks good to me.

Thanks also for breaking this off into a separate crate. I think it is better that way.

haiku/src/implementation.cc Show resolved Hide resolved
`iana-time-zone` depends on `iana-time-zone-haiku` depends on
`cxx-build` depends on `codespan-reporting` depends on `termcolor`.

With `-Zminimal-versions` `termcolor==1.0.0` is selected, but
`codespan-reporting` actually needs `termcolor>=1.0.4`.

We could either depend on `termcolor >= 1.0.4"` to fix the problem
... or we can ignore it.
@astraw
Copy link
Member

astraw commented Oct 1, 2022

We have 2 approvals now, so according to our Unsafe-Proposed policy (#64), let's let this sit until 8 October and then merge.

@astraw
Copy link
Member

astraw commented Oct 1, 2022

@Kijewski thanks for the work on this, including shifting most of it to its own crate.

@Kijewski Kijewski added the Tier-3 Rust Tier-3 platform label Oct 1, 2022
@astraw astraw merged commit fd3d810 into strawlab:main Oct 8, 2022
@Kijewski Kijewski deleted the pr-haiku branch December 13, 2022 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tier-3 Rust Tier-3 platform Unsafe-Proposed `unsafe` code is added or changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants