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

Adding Rust Code with Elixir Bindings #1

Merged
merged 19 commits into from
May 28, 2024
Merged

Conversation

bradschwartz
Copy link
Collaborator

@bradschwartz bradschwartz commented Apr 30, 2024

Adds all the initial functionality. API looks like:

JsonSchemaNif.validate_json(~S/{"age":30}/, ~S/{"type":"string"}/)

On PRs, we'll compile the Elixir project with RUSTLER_PRECOMPILATION_FORCE_BUILD=true . For some weird reason I couldn't get this to compile on Ubuntu 20.04 with Elixir 1.16 and OTP 25 - other OTP versions worked fine. See this Run for example error: https://github.com/podium/json_schema_nif/actions/runs/8913023798. For this reason, just running on ubuntu-latest for the Elixir CI. We also run the NIF compilation on PRs, but only push the artifacts on tag creation.

Currently, not set up to run any sort of Rust specific checks like formatting or clippy.

MIT License.

@bradschwartz bradschwartz marked this pull request as ready for review May 1, 2024 18:35
on:
pull_request:
branches:
- master

Choose a reason for hiding this comment

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

Will this run the release workflow on any pull requests to master? Just making sure that's the desired behavior. Looks like things are only published on a tag, so in other cases is this so one could pull down a built/uploaded artifact and check something manually?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These will run on PR to master, on master, and on the creation of new tags. Maybe calling it release.yml is a bit of a misnomer since I'm also using it just to check that all the NIFs/rust code compiles. I'm fine with it publishing artifacts on non-tags, but i also don't see a huge gain in doing it. Most of this is copied from https://github.com/philss/rustler_precompiled?tab=readme-ov-file ( or links) .

- master
push:
branches:
- main

Choose a reason for hiding this comment

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

Will this repo have a "main" branch separate from "master" (which seems to be current default)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nope, just copy-pasta

rustler::atoms! {
bad_instance,
bad_schema,
matches_schema,

Choose a reason for hiding this comment

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

I don't know if rustler has a good way to do this or if you'd have to wrap it, but in my opinion in feels a little odd to return {:ok, :matches_schema} instead of just :ok

🤷 not a big deal, though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Locally I see this:

iex(1)> JsonSchemaNif.validate_json(~S/{"age":30}/, ~S/{"type":"string"}/)
{:error, :violates_schema}
iex(3)> JsonSchemaNif.validate_json(~S/{"age":"thirty"}/, ~S/{"type":"object"}/)
{:ok, :matches_schema}

So I think we already have the behavior you're asking for?

Copy link
Contributor

Choose a reason for hiding this comment

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

II think his point is to return ok only. not a tuple. I could agree with that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, just pushed this change

let instance_value = match serde_json::from_str::<Value>(&instance) {
Ok(val) => val,
Err(err) => {
error!("Failed to parse JSON: {:?}", err);
Copy link

@brettbeatty brettbeatty May 1, 2024

Choose a reason for hiding this comment

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

Are these errors being logged? Are the err values something that would be easy to send to Elixir? I could just see not wanting to log these, so I'm wondering if they could be returned like

{:error, {:bad_schema, "Unexpected char '<'"}} # not sure what err looks like

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so, at least I can't seem to make it show up in iex 🤷

elixir_version: [1.15]
otp_version: [24, 25, 26]
exclude:
- otp_version: 26
Copy link
Contributor

Choose a reason for hiding this comment

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

can remove all exclusion here.. remove OITP 24

lets just do 1.15, 1.16, and then OTP 25 and 26

@@ -0,0 +1,5 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We don't totally need it, but without it vscode fails to recognize that there is also a rust project in this codebase. If you feel strongly, i'm happy to remove

CHANGELOG.md Outdated

## [Unreleased]

## [0.1.0] - 2023-11-17
Copy link
Contributor

Choose a reason for hiding this comment

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

adjust date ?

mix.exs Show resolved Hide resolved
renovate.json Outdated
@@ -0,0 +1,4 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

are we not using dependabot here? that s the default on github

renovate.json Outdated
@@ -0,0 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["local>engineering/ops/renovate-config"]
Copy link
Contributor

Choose a reason for hiding this comment

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

this is only for gitlab. I suspect

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep good call, will scrub from history

epinault
epinault previously approved these changes May 15, 2024
Copy link
Contributor

@epinault epinault left a comment

Choose a reason for hiding this comment

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

Approved. Check with Brett if he is good too

.iex.exs Outdated Show resolved Hide resolved
@bradschwartz bradschwartz merged commit b64b65d into master May 28, 2024
24 checks passed
@bradschwartz bradschwartz deleted the init-functionality branch May 28, 2024 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants