-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from podium/init-functionality
Adding Rust Code with Elixir Bindings
- Loading branch information
Showing
25 changed files
with
2,074 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
Validating CODEOWNERS rules …
This file contains 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 @@ | ||
* @podium/oss-engineers |
This file contains 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,23 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report to help us improve | ||
title: '' | ||
labels: bug | ||
assignees: epinault | ||
|
||
--- | ||
|
||
**Describe the bug** | ||
A clear and concise description of what the bug is. | ||
|
||
** Provide the following details | ||
|
||
- Elixir version (elixir -v): | ||
- Erlang version (erl -v): | ||
- Operating system: | ||
|
||
**Expected behavior** | ||
A clear and concise description of what you expected to happen. | ||
|
||
**Actual behavior** | ||
A clear and concise description of what actually happens. |
This file contains 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,12 @@ | ||
version: 2 | ||
updates: | ||
# Maintain dependencies for GitHub Actions | ||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
|
||
- package-ecosystem: "mix" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains 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,55 @@ | ||
name: Elixir CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
env: | ||
MIX_ENV: test | ||
RUSTLER_PRECOMPILATION_FORCE_BUILD: true | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
elixir_version: [1.15, 1.16] | ||
otp_version: [25, 26] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: erlef/setup-beam@v1 | ||
with: | ||
otp-version: ${{matrix.otp_version}} | ||
elixir-version: ${{matrix.elixir_version}} | ||
|
||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- uses: actions/cache@v4 | ||
with: | ||
path: | | ||
deps | ||
_build | ||
key: deps-${{ runner.os }}-${{ matrix.otp_version }}-${{ matrix.elixir_version }}-${{ hashFiles('**/mix.lock') }} | ||
restore-keys: | | ||
deps-${{ runner.os }}-${{ matrix.otp_version }}-${{ matrix.elixir_version }} | ||
- run: mix deps.get | ||
|
||
- run: mix format --check-formatted | ||
|
||
- run: mix deps.unlock --check-unused | ||
|
||
- run: mix deps.compile | ||
|
||
- run: mix compile --warnings-as-errors | ||
|
||
- run: mix credo --strict --format=oneline | ||
|
||
- run: mix test --warnings-as-errors --cover |
This file contains 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,92 @@ | ||
name: Build Precompiled NIFs | ||
# lifted from: https://github.com/philss/rustler_precompilation_example/blob/main/.github/workflows/release.yml | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
push: | ||
branches: | ||
- master | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
build_release: | ||
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) | ||
runs-on: ${{ matrix.job.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
nif: ["2.16", "2.15"] | ||
job: | ||
- { | ||
target: arm-unknown-linux-gnueabihf, | ||
os: ubuntu-20.04, | ||
use-cross: true, | ||
} | ||
- { | ||
target: aarch64-unknown-linux-gnu, | ||
os: ubuntu-20.04, | ||
use-cross: true, | ||
} | ||
- { | ||
target: aarch64-unknown-linux-musl, | ||
os: ubuntu-20.04, | ||
use-cross: true, | ||
} | ||
- { target: aarch64-apple-darwin, os: macos-11 } | ||
- { | ||
target: riscv64gc-unknown-linux-gnu, | ||
os: ubuntu-20.04, | ||
use-cross: true, | ||
} | ||
- { target: x86_64-apple-darwin, os: macos-11 } | ||
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 } | ||
- { | ||
target: x86_64-unknown-linux-musl, | ||
os: ubuntu-20.04, | ||
use-cross: true, | ||
} | ||
- { target: x86_64-pc-windows-gnu, os: windows-2019 } | ||
- { target: x86_64-pc-windows-msvc, os: windows-2019 } | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Extract project version | ||
shell: bash | ||
run: | | ||
# Get the project version from mix.exs | ||
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV | ||
- name: Install Rust toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
toolchain: stable | ||
target: ${{ matrix.job.target }} | ||
|
||
- name: Build the project | ||
id: build-crate | ||
uses: philss/[email protected] | ||
with: | ||
project-name: json_schema_nif | ||
project-version: ${{ env.PROJECT_VERSION }} | ||
target: ${{ matrix.job.target }} | ||
nif-version: ${{ matrix.nif }} | ||
use-cross: ${{ matrix.job.use-cross }} | ||
project-dir: "native/json_schema_nif" | ||
|
||
- name: Artifact upload | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: ${{ steps.build-crate.outputs.file-name }} | ||
path: ${{ steps.build-crate.outputs.file-path }} | ||
|
||
- name: Publish archives and packages | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
${{ steps.build-crate.outputs.file-path }} | ||
if: startsWith(github.ref, 'refs/tags/') |
This file contains 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,31 @@ | ||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
json_schema_nif-*.tar | ||
|
||
# Temporary files, for example, from tests. | ||
/tmp/ | ||
|
||
# --- | ||
|
||
# Rustler | ||
*.so |
This file contains 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,35 @@ | ||
IO.puts("Using .iex.exs file loaded from #{__DIR__}/.iex.exs") | ||
|
||
defmodule :_util do | ||
defdelegate exit(), to: System, as: :halt | ||
defdelegate q(), to: System, as: :halt | ||
defdelegate restart(), to: System, as: :restart | ||
|
||
def atom_status do | ||
limit = :erlang.system_info(:atom_limit) | ||
count = :erlang.system_info(:atom_count) | ||
|
||
IO.puts("Currently using #{count} / #{limit} atoms") | ||
end | ||
|
||
def cls, do: IO.puts("\ec") | ||
|
||
def raw(any, label \\ "iex") do | ||
IO.inspect(any, | ||
label: label, | ||
pretty: true, | ||
limit: :infinity, | ||
structs: false, | ||
syntax_colors: [ | ||
number: :yellow, | ||
atom: :cyan, | ||
string: :green, | ||
nil: :magenta, | ||
boolean: :magenta | ||
], | ||
width: 0 | ||
) | ||
end | ||
end | ||
|
||
import :_util |
This file contains 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,2 @@ | ||
elixir 1.15.7-otp-26 | ||
erlang 26.1.1 |
This file contains 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,5 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"./native/json_schema_nif/Cargo.toml" | ||
] | ||
} |
This file contains 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,16 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic | ||
Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [0.1.0] - 2024-05-15 | ||
|
||
Initial release. | ||
|
||
### Added | ||
|
||
- `JsonSchemaNif.validate_json/2` to validate a JSON instance against a provided JSON schema. |
This file contains 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,40 @@ | ||
# Contributing | ||
|
||
This library is kept intentionally simple. | ||
|
||
That said, contributions (especially bug fixes!) are welcome. To contribute: | ||
|
||
- Propose the changes as a GitHub Issue | ||
- If feedback is supportive, create a new branch for your feature or bug fix | ||
- Implement your changes | ||
- Write tests for your changes | ||
- Document your changes | ||
- Ensure all tests pass | ||
- Submit a merge request | ||
|
||
# Building the Project | ||
|
||
Build dependencies: | ||
|
||
1. Elixir toolchain (default to asdf installation) | ||
1. Rust toolchain | ||
|
||
To force a compilation of the Rust portions locally, instead of relying | ||
on pre-built artifacts, set `RUSTLER_PRECOMPILATION_FORCE_BUILD=true`. | ||
|
||
```bash | ||
cd native/json_schema_nif/ | ||
# If you need extra toolchains | ||
rustup target add x86_64-apple-darwin | ||
rustup target add aarch64-apple-darwin | ||
rustup target add aarch64-unknown-linux-gnu | ||
|
||
cargo build --target aarch64-unknown-linux-gnu --release | ||
cargo build --target aarch64-apple-darwin --release | ||
cargo build --target x86_64-apple-darwin --release | ||
``` | ||
|
||
To generate the checksum file **after** the NIF files have been uploaded to GitHub, | ||
run: `mix rustler_precompiled.download JsonSchemaNif --only-local`. | ||
|
||
These files are required as part of the Hex package, but don't need to be tracked in VCS. |
This file contains 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,8 @@ | ||
The MIT License (MIT) | ||
Copyright (c) 2024 Podium | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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.