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

Hurl parser attempt PR #553

Merged
merged 5 commits into from
Feb 1, 2025
Merged

Hurl parser attempt PR #553

merged 5 commits into from
Feb 1, 2025

Conversation

WrathOP
Copy link
Contributor

@WrathOP WrathOP commented Jan 26, 2025

PR Description

This PR is regarding the writeup for all the things that worked and I got working for the hurl parser for the project.

Brief on what worked:
Got it working on macos and linux.

Issues:
Can't get it working on mobile platforms.

Related Issues

  • Closes #

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I am using the latest Flutter stable branch (run flutter upgrade and verify)
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

We encourage you to add relevant test cases.

  • Yes
  • No, and this is why: Just docs are being updated

OS on which you have developed and tested the feature?

  • Windows
  • macOS
  • Linux

@@ -0,0 +1,67 @@
### Feature Implementation Writeup: HurlParser Wrapper for API Dash
Copy link
Member

Choose a reason for hiding this comment

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

Title => Flutter Rust Bridge Experiment for parsing Hurl


#### Transition to Hurl Parser Wrapper Using Flutter Rust Bridge

Following the maintainer's suggestion, I began developing a wrapper for the Hurl parser using `flutter_rust_bridge`. Since the documentation for the library can be sparse, I’ve documented my steps for clarity:
Copy link
Member

@ashitaprasad ashitaprasad Jan 30, 2025

Choose a reason for hiding this comment

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

As the documentation is sparse, add relevant links on useful examples ... how to start with flutter_rust_bridge ... how it works .. its architecture. .. how it works across platforms ..

This is a technical document which must cover things you learnt while exploring.

1. **Creating the Library:**

- I ran the command:
`flutter_rust_bridge_codegen create hurl --template plugin`
Copy link
Member

Choose a reason for hiding this comment

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

The steps are incomplete. Where did you run this command? inside apidash or inside a new package you created .. be as clear as possible.


2. **Adding the Parse Function:**

- I added the library code and the `parse_hurl` function in `rust/src/api/simple.rs`.
Copy link
Member

Choose a reason for hiding this comment

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

What code was added? Where and why? add code snippets. ..

@@ -0,0 +1,67 @@
### Feature Implementation Writeup: HurlParser Wrapper for API Dash

I initially started with the approach of writing my own parser using `petitparser` and creating a custom implementation. However, after about a week, the maintainer recommended against this approach. They highlighted that building a custom parser would lack future-proofing if `hurl.dev` were to implement changes. While I abandoned this route, the code is still available in a branch. My custom parser had progressed to the point where requests and assertions were working, though it was far from complete.
Copy link
Member

Choose a reason for hiding this comment

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

The whole idea of this technical document should be that if I read it ... I must understand what flutter_rust_bridge is .. how it works .. how I can integrate it .. whats are its advantages and disadvantages.

`flutter_rust_bridge_codegen generate`
- This generated all the necessary code for Flutter and all the targeted platforms.

`flutter_rust_bridge` uses a tool called `cargokit` to manage dependencies, acting as a glue layer between Flutter and Rust. Unfortunately, `cargokit` is still experimental, with little documentation available. The [blog post by Matej Knopp](https://matejknopp.com/post/flutter_plugin_in_rust_with_no_prebuilt_binaries/) provided valuable insights. One crucial takeaway was avoiding the Homebrew installation of Rust and instead using `rustup`. This resolved platform compilation issues for me, though the project is still not compiling entirely.
Copy link
Member

Choose a reason for hiding this comment

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

cargokit doc should be linked


Based on this, I created models in Dart using the `freezed` package. The goal was to convert the JSON output from the Hurl parser into Dart data models. I am confident this part turned out well.

After writing tests for Hurl parsing and model generation, I shifted focus to building the project.
Copy link
Member

Choose a reason for hiding this comment

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

It is not "Implementing the Wrapper" rather building Dart models.


After writing tests for Hurl parsing and model generation, I shifted focus to building the project.

#### Compilation Challenges
Copy link
Member

Choose a reason for hiding this comment

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

Compilation steps are missing ... you directly jumped to challenges.


This fixed the macOS build.

However, testing on iOS and Android proved problematic, as I didn’t have access to Windows or Linux systems. For iOS, adding similar flags didn’t work. I tried various fixes, such as modifying the header search paths, linking frameworks, and changing build phases in Xcode, but none succeeded.
Copy link
Member

Choose a reason for hiding this comment

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

How do people use this library in iOS & Android? Is it hurl_parser specific problem or flutter_rust_bridge limitation? Add more technical details.


During compilation, I encountered an issue, which I reported on the [Hurl repository](https://github.com/Orange-OpenSource/hurl/issues/3603). The Hurl parser depends on the `libxml2` crate for XML parsing. To resolve this, I had to add:

`OTHER_LDFLAGS => -force_load ${BUILT_PRODUCTS_DIR}/libhurl.a -lxml2`
Copy link
Member

Choose a reason for hiding this comment

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

where? steps are missing.


At this point, I’ve committed all my code to the repository in a fork. Here are some potential solutions I believe might work:

1. **Use Dart Native FFIs**: Currently under an experimental flag, as suggested by the `flutter_rust_bridge` maintainer.
Copy link
Member

Choose a reason for hiding this comment

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

Link?

Current Branches in my fork:

- [Hurl Parser with flutter_rust_bridge](https://github.com/WrathOP/apidash/tree/hurl-parser-rust)
- [Hurl Parser with petiteparser](https://github.com/WrathOP/apidash/tree/hurl-parser-added)
Copy link
Member

Choose a reason for hiding this comment

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

Like I said before .. more technical details can be added ... Also some diagrams can be added if it helps. ..
It can be crafted into a high quality reference for flutter_rust_bridge
Also, you can add more examples if you got another rust library successfully integrated and working across both desktop and mobile.

- Tried to make it more informative
- Added more links and code snippets
@WrathOP
Copy link
Contributor Author

WrathOP commented Feb 1, 2025

@ashitaprasad I have tried to add more detail to the document thanks for your comments earlier. I have not written a writeup or docs before so I am getting a hang of it. Do let me know if there are any other improvements I can make.

@ashitaprasad
Copy link
Member

ashitaprasad commented Feb 1, 2025

Thank you for undertaking this experiment and documenting your findings. It is definitely a valuable guide showing the challenges one can face when using flutter_rust_bridge in a real life project.

The issue lies in hurl_core which uses libxml. So looks like the way forward is the custom implementation which can be verified agains the hurlfmt rust package results.

@ashitaprasad ashitaprasad merged commit 87f799b into foss42:main Feb 1, 2025
@ashitaprasad ashitaprasad mentioned this pull request Feb 1, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants