Skip to content

Commit

Permalink
Use Rustler Precompiled and prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtaylor committed Mar 6, 2024
1 parent f84059b commit aec7bf1
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 7 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build precompiled NIFs

on:
push:
branches:
- main
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.15"]
job:
- { target: aarch64-apple-darwin, os: macos-11 }
- {
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: arm-unknown-linux-gnueabihf,
os: ubuntu-20.04,
use-cross: true,
}
- {
target: riscv64gc-unknown-linux-gnu,
os: ubuntu-20.04,
use-cross: true,
}
- { target: x86_64-apple-darwin, os: macos-11 }
- { target: x86_64-pc-windows-gnu, os: windows-2019 }
- { target: x86_64-pc-windows-msvc, os: windows-2019 }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 }
- {
target: x86_64-unknown-linux-musl,
os: ubuntu-20.04,
use-cross: true,
}

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: h3geo
project-version: ${{ env.PROJECT_VERSION }}
target: ${{ matrix.job.target }}
nif-version: ${{ matrix.nif }}
use-cross: ${{ matrix.job.use-cross }}
project-dir: "native/h3geo"

- 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/')
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.1.0

- Initial release
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Tom Taylor

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.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# H3Geo

[![Hex pm](http://img.shields.io/hexpm/v/h3geo.svg?style=flat)](https://hex.pm/packages/h3geo)
[![HexDocs](https://img.shields.io/badge/HexDocs-Yes-blue)](https://hexdocs.pm/h3geo)

Implements H3, the hexagonal hierarchical geospatial indexing system, in Elixir. Behind the scenes it uses h3o, a Rust implementation of H3.

This library is in early stages of development and currently only exposes a handful of functions from h3o for converting different geometries to cells.
Expand All @@ -14,12 +17,14 @@ def deps do
end
```

The NIF is provided as a precompiled bundle, so you won't need to install Rust to use it.

## Example

```elixir
point = %Geo.Point{coordinates: {-0.14234062595533195, 51.50107677017966}}
precision = 6
cell = H3Geo.point_to_cell(point, precision)
{:ok, cell} = H3Geo.point_to_cell(point, precision)
Integer.to_string(cell, 16)
# "86194AD17FFFFFF"
```
9 changes: 7 additions & 2 deletions lib/h3_geo.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
defmodule H3Geo do
use Rustler,
version = Mix.Project.config()[:version]

use RustlerPrecompiled,
otp_app: :h3geo,
crate: :h3geo
crate: :h3geo,
base_url: "https://github.com/breakroom/h3geo/releases/download/v#{version}",
force_build: System.get_env("H3GEO_BUILD") in ["1", "true"],
version: version

@doc """
Takes a `Geo.Point` and an `Integer` precision and returns an integer
Expand Down
41 changes: 37 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,29 +1,62 @@
defmodule H3Geo.MixProject do
use Mix.Project

@version "0.1.0-dev"
@github_url "https://github.com/breakroom/h3geo"

def project do
[
app: :h3geo,
version: "0.1.0",
name: "H3Geo",
description: "H3 geospatial indexing library",
version: @version,
elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
deps: deps()
deps: deps(),
package: package(),
docs: docs()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:rustler, "~> 0.31"},
{:rustler_precompiled, "~> 0.7"},
{:geo, "~> 3.6"},
{:ex_doc, "~> 0.31", only: :dev, runtime: false}
]
end

defp package do
[
maintainers: ["Tom Taylor"],
licenses: ["MIT"],
links: %{
"GitHub" => @github_url
},
files: [
"lib",
"native/h3geo/.cargo",
"native/h3geo/src",
"native/h3geo/Cargo*",
"checksum-*.exs",
"mix.exs",
"LICENSE"
]
]
end

defp docs do
[
main: "H3Geo",
extras: ["README.md", "CHANGELOG.md"],
source_ref: @version
]
end
end
2 changes: 2 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%{
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"ex_doc": {:hex, :ex_doc, "0.31.2", "8b06d0a5ac69e1a54df35519c951f1f44a7b7ca9a5bb7a260cd8a174d6322ece", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "317346c14febaba9ca40fd97b5b5919f7751fb85d399cc8e7e8872049f37e0af"},
"geo": {:hex, :geo, "3.6.0", "00c9c6338579f67e91cd5950af4ae2eb25cdce0c3398718c232539f61625d0bd", [:mix], [{:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "1dbdebf617183b54bc3c8ad7a36531a9a76ada8ca93f75f573b0ae94006168da"},
Expand All @@ -8,5 +9,6 @@
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"rustler": {:hex, :rustler, "0.31.0", "7e5eefe61e6e6f8901e5aa3de60073d360c6320d9ec363027b0197297b80c46a", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "99e378459bfb9c3bda6d3548b2b3bc6f9ad97f728f76bdbae7bf5c770a4f8abd"},
"rustler_precompiled": {:hex, :rustler_precompiled, "0.7.1", "ecadf02cc59a0eccbaed6c1937303a5827fbcf60010c541595e6d3747d3d0f9f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "b9e4657b99a1483ea31502e1d58c464bedebe9028808eda45c3a429af4550c66"},
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
}

0 comments on commit aec7bf1

Please sign in to comment.