Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ jobs:
# - "nightly"
os:
- ubuntu-latest
# turn of windows for now until someone fixes the Cmd issues
# - windows-latest
- windows-latest
- macos-latest
arch:
- x64
- aarch64
exclude:
- os: ubuntu-latest
arch: aarch64
# # windows does not support aarch64 yet
# - os: windows-latest
# arch: aarch64
- os: windows-latest
arch: aarch64
# libosrmc does not support x64 on macOS yet
- os: macos-latest
arch: x64
Expand Down
9 changes: 6 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name = "OpenSourceRoutingMachine"
uuid = "19e5a071-0e58-4e20-9e36-393e8533d14d"
license = "MIT"
authors = ["MOVIRO GmbH <info@moviro.com>"]
version = "0.2.1"
authors = ["MOVIRO GmbH <info@moviro.com>"]

[deps]
EnumX = "4e289a0a-7415-4d19-859d-a7e5c4648b56"
Expand All @@ -11,9 +11,12 @@ Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
OSRM_jll = "a74304e1-5a13-544f-adb7-0572470cee19"
libosrmc_jll = "b012619c-76c7-5216-bb6b-491eaf671aba"

[sources]
libosrmc_jll = {rev = "main", url = "https://github.com/jrklasen/libosrmc_jll.jl"}

[compat]
EnumX = "1.0.5"
FlatBuffers = "0.6.2"
OSRM_jll = "~6.0.0"
OSRM_jll = "~26.4.0"
julia = "1.11.0"
libosrmc_jll = "=6.0.2"
libosrmc_jll = "=26.4.0"
34 changes: 15 additions & 19 deletions gen/README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
# FlatBuffers Type Generator

Tools for automatically generating Julia type definitions from OSRM's [FlatBuffers](https://flatbuffers.dev/) schema files. The OSRM backend uses FlatBuffers to serialize API responses, and this generator parses the `.fbs` schema files to produce equivalent Julia type definitions.

## Components

- **`Generator.jl`**: Main module containing code for downloading schema files from the OSRM GitHub repository, parsing `.fbs` files to extract enums/structs/tables, mapping FlatBuffers types to Julia equivalents, and generating Julia code with proper dependency resolution.

- **`generate.jl`**: Convenience script uses the Module to download schemas and generates `../src/types.jl`. Configured for OSRM `v6.0.0` by default; update `OSRM_VERSION` in the script for other versions.
Generates Julia type definitions from OSRM's [FlatBuffers](https://flatbuffers.dev/) schema files. The OSRM backend uses FlatBuffers to serialize API responses; this generator parses the `.fbs` schemas and produces equivalent Julia types for use with `FlatBuffers.jl`.

## Usage

Run from this directory:

```bash
cd gen
julia generate.jl
```

This downloads schema files (`fbresult.fbs`, `route.fbs`, `table.fbs`, `position.fbs`, `waypoint.fbs`) to `flatbuffers/`, parses them and their includes, and generates `../src/types.jl`.
This downloads schema files to `flatbuffers/`, parses them, and generates `../src/types.jl`.

## How It Works
## Structure

1. **Download**: Fetches `.fbs` files from the OSRM repository at the specified version tag.
2. **Parse**: Extracts enums, structs, and tables, tracking include relationships.
3. **Generate**: Resolves dependencies, topologically sorts types, and generates Julia code with `@cenum` definitions, immutable structs, and mutable table structs.
4. **Output**: Writes generated code to `src/types.jl`.
| File | Responsibility |
|------|---------------|
| `generate.jl` | Entry script — configuration and orchestration |
| `src/Generator.jl` | Module wrapper |
| `src/types.jl` | Type maps (FBS -> Julia) and IR structs |
| `src/download.jl` | Download `.fbs` files from GitHub |
| `src/parsing.jl` | Parse `.fbs` files into IR |
| `src/dependencies.jl` | Topological sorting of type definitions |
| `src/generation.jl` | Emit Julia source code from IR |

## Updating for New Versions
## Updating for a new OSRM version

1. Edit `OSRM_VERSION` in `generate.jl` (e.g., `"v6.1.0"`)
1. Edit `OSRM_VERSION` in `generate.jl` (currently `v26.4.0`)
2. Run `julia generate.jl`
3. Review `src/types.jl` for breaking changes

The generator handles includes automatically and ensures types are properly referenced across files.
2 changes: 2 additions & 0 deletions gen/flatbuffers/route.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ table Leg {
summary: string;
annotations: Annotation;
steps: [Step];
polyline: string;
coordinates: [Position];
}

table RouteObject {
Expand Down
29 changes: 12 additions & 17 deletions gen/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
include("src/Generator.jl")
using .Generator: download_flatbuffers, generate_julia_code

# Configuration constants
const OSRM_VERSION = "v6.0.0"

# --- Configuration ---
const OSRM_VERSION = "v26.4.0"
const BASE_URL = "https://raw.githubusercontent.com/Project-OSRM/osrm-backend"
const FBS_SUBDIR = "include/engine/api/flatbuffers"
const DOWNLOAD_FILES = [
Expand All @@ -16,33 +15,29 @@ const DOWNLOAD_FILES = [
"waypoint.fbs",
]

# Path constants relative to script location
# --- Paths (relative to this script) ---
const SCRIPT_DIR = @__DIR__
const FLATBUFFERS_DIR = joinpath(SCRIPT_DIR, "flatbuffers")
const SRC_DIR = joinpath(SCRIPT_DIR, "..", "src")


const INPUT_FILE = joinpath(FLATBUFFERS_DIR, "fbresult.fbs")
const OUTPUT_FILE = joinpath(SRC_DIR, "types.jl")

# Step 1: Download flatbuffer files
# --- Step 1: Download ---
println("Step 1: Downloading FlatBuffer schema files...")
println("-"^60)
success = download_flatbuffers(OSRM_VERSION; base_url = BASE_URL, subdir = FBS_SUBDIR, files = DOWNLOAD_FILES, output_dir = FLATBUFFERS_DIR)
if !success
println()
println("Error: Failed to download some FlatBuffer files")
if !download_flatbuffers(OSRM_VERSION; base_url = BASE_URL, subdir = FBS_SUBDIR, files = DOWNLOAD_FILES, output_dir = FLATBUFFERS_DIR)
println("\nError: Failed to download some FlatBuffer files")
exit(1)
end

# Step 2: Generate Julia code
# --- Step 2: Generate ---
println("Step 2: Generating Julia code...")
println("-"^60)
success = generate_julia_code(INPUT_FILE, OUTPUT_FILE)
if !success
println()
println("Error: Failed to generate Julia code")
if !generate_julia_code(INPUT_FILE, OUTPUT_FILE)
println("\nError: Failed to generate Julia code")
exit(1)
end

println("="^60)
println("Successfully completed all steps!")
println("Done.")
println("="^60)
15 changes: 4 additions & 11 deletions gen/src/Generator.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
"""
Generator

Module for generating Julia code from FlatBuffers schema files.
Module for generating Julia type definitions from FlatBuffers schema files.

This module provides functionality to download FlatBuffers schema files from the OSRM
GitHub repository, parse `.fbs` files to extract enums, structs, and tables, map
FlatBuffers types to Julia equivalents, and generate Julia code with proper dependency
resolution.

The main entry points are:
- [`download_flatbuffers`](@ref): Download schema files from a GitHub repository
- [`generate_julia_code`](@ref): Generate Julia type definitions from FlatBuffers schemas
Provides two entry points:
- [`download_flatbuffers`](@ref): Download `.fbs` schema files from the OSRM GitHub repository
- [`generate_julia_code`](@ref): Parse schemas and generate Julia code with dependency resolution
"""
module Generator

using Downloads

# Include all module files in dependency order
include("types.jl")
include("download.jl")
include("parsing.jl")
include("dependencies.jl")
include("generation.jl")

# Exports
export download_flatbuffers, generate_julia_code

end # module Generator
Loading
Loading