Skip to content
Open
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
78 changes: 78 additions & 0 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: "Rust CI"

on:
push:
branches:
- master
- 'release-*'
paths:
- computer-rust/**
- .github/workflows/rust-ci.yml
pull_request:
paths:
- computer-rust/**
- .github/workflows/rust-ci.yml

defaults:
run:
working-directory: computer-rust

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rust-check:
name: Rust Code Quality & Tests
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt

- name: Cache Cargo dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
computer-rust/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('computer-rust/Cargo.toml') }}
restore-keys: ${{ runner.os }}-cargo-

- name: Check code formatting
run: cargo fmt --check

- name: Run clippy lints
run: cargo clippy --all-targets -- -D warnings

- name: Run tests
run: cargo test --all-targets --verbose

- name: Build release library
run: cargo build --release

- name: Build benchmarks
run: cargo bench --no-run
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ header: # `header` section is configurations for source codes license header.
- '**/target/*'
- '**/go.mod'
- '**/go.sum'
- '**/Cargo.lock'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 This exclusion is added for a file the PR never commits. git ls-tree -r --name-only c1fc10a -- computer-rust lists twelve files and no Cargo.lock, and .gitignore has no Cargo entry, so the entry is dead config today and the crate builds unpinned.

That matters for the new gate. .github/workflows/rust-ci.yml:69 runs cargo clippy --all-targets -- -D warnings on a floating dtolnay/rust-toolchain@stable against freshly resolved dependencies, so a new clippy lint or an upstream minor release turns the gate red on the next unrelated Rust PR, with no lockfile to bisect against. The cache key hashFiles('computer-rust/Cargo.toml') (rust-ci.yml:62) cannot see resolution changes that a lockfile would capture either.

Please commit computer-rust/Cargo.lock, which is what this exclusion and the neighbouring committed go.mod/go.sum entries imply was intended. A rust-toolchain.toml would pin the other half.

comment: on-failure # on what condition license-eye will comment on the pull request, `on-failure`, `always`, `never`.

# license-location-threshold specifies the index threshold where the license header can be located,
Expand Down
43 changes: 43 additions & 0 deletions computer-rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

[package]
name = "hugegraph-computer-rust"
version = "1.5.0"
edition = "2021"
authors = ["Apache HugeGraph Authors <dev@hugegraph.apache.org>"]
license = "Apache-2.0"
description = "High-performance Rust graph computing kernels for HugeGraph Computer and Vermeer"
repository = "https://github.com/apache/hugegraph-computer"

[lib]
name = "hugegraph_computer_rust"
crate-type = ["cdylib", "staticlib", "rlib"]

[dependencies]
libc = "0.2"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 libc is declared but never used. git grep -n libc c1fc10a -- computer-rust returns this line and nothing else; the FFI layer uses std::ffi::CString, std::os::raw::c_char and std::slice (src/ffi/c_api.rs:23-25). Neither cargo build nor the new cargo clippy --all-targets -- -D warnings gate reports an unused dependency, so this will not surface on its own.

Please drop it, or switch c_api.rs to libc::c_char if a future no_std path is the intent. Declaring it while using std::os::raw gets the cost without the benefit.


[dev-dependencies]
criterion = "0.5"

[[bench]]
name = "kernel_bench"
harness = false

[profile.release]
opt-level = 3
lto = true
codegen-units = 1
panic = "abort"
31 changes: 31 additions & 0 deletions computer-rust/benches/kernel_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use criterion::{criterion_group, criterion_main, Criterion};
use hugegraph_computer_rust::fixtures::dataset::GraphFixture;
use hugegraph_computer_rust::kernel::pagerank::PageRankKernel;

fn bench_pagerank(c: &mut Criterion) {
let fixture = GraphFixture::synthetic_powerlaw(1000, 10);
let csr = fixture.to_csr();
let kernel = PageRankKernel::new(0.85, 20, 1e-4);

c.bench_function("pagerank_1k_vertices", |b| b.iter(|| kernel.compute(&csr)));
}

criterion_group!(benches, bench_pagerank);
criterion_main!(benches);
83 changes: 83 additions & 0 deletions computer-rust/include/computer_rust_c_api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef HUGEGRAPH_COMPUTER_RUST_C_API_H
#define HUGEGRAPH_COMPUTER_RUST_C_API_H

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct GraphHandle GraphHandle;

/**
* Creates a new GraphHandle instance with the specified number of vertices.
*/
GraphHandle* computer_graph_create(uint32_t num_vertices);

/**
* Adds a directed edge from src to dst with a weight.
* @return 0 on success.
* @return -1 if handle is NULL, endpoints src/dst are >= num_vertices, or weight < 0.0 or non-finite.
* @return -2 if graph has already been finalized.
*/
int32_t computer_graph_add_edge(GraphHandle* handle, uint32_t src, uint32_t dst, double weight);

/**
* Finalizes graph topology into Compressed Sparse Row (CSR) structure.
* @return 0 on success, -1 if handle is NULL.
*/
int32_t computer_graph_finalize(GraphHandle* handle);

/**
* Computes PageRank on the CSR graph structure.
* Results array must be allocated by caller with capacity >= num_vertices.
* @return 0 on success.
* @return -1 if handle or out_scores is NULL.
* @return -2 if graph is not finalized (CSR missing).
* @return -3 if out_capacity < num_vertices.
* @return -4 if damping_factor or tolerance is invalid (non-finite, negative, or damping > 1.0).
*/
int32_t computer_graph_compute_pagerank(
const GraphHandle* handle,
double damping_factor,
uint32_t max_iterations,
double tolerance,
double* out_scores,
uint32_t out_capacity
);

/**
* Frees the GraphHandle resources.
*/
void computer_graph_free(GraphHandle* handle);

/**
* Returns the version string of the Rust kernel library.
* Pointer references process-lifetime static storage and remains valid across threads.
*/
const char* computer_kernel_version(void);

#ifdef __cplusplus
}
#endif

#endif /* HUGEGRAPH_COMPUTER_RUST_C_API_H */
Loading