Skip to content

Commit ed7579a

Browse files
committed
chore: Create workspace for developing uplink crate
Create a Cargo workspace for developing the `uplink` crate in this same repository. The `uplink` crate is the idiomatic and safe Rust binding for Storj uplink wrapping the existing `uplink-sys` crate. The commit * moves some files or content from the root of the repository to the "uplink-sys" directory, which is where the crate with the same name is implemented. * initializes the `uplink` crate under a subdirectory with the same name, for implementing it. * creates a workspace including these two creates as members.
1 parent a4603df commit ed7579a

File tree

10 files changed

+157
-123
lines changed

10 files changed

+157
-123
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[workspace]
2+
members = ["uplink", "uplink-sys"]

README.md

+8-100
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,16 @@
11
# uplink-rust
22

3-
[![Actions Status](https://github.com/storj-thirdparty/uplink-rust/workflows/uplink-sys/badge.svg)](https://github.com/storj-thirdparty/uplink-rust/actions)
4-
[![Crates.io](https://img.shields.io/crates/v/uplink-sys)](https://crates.io/crates/uplink-sys)
3+
Storj Uplink Rust bindings for the Rust programming language.
54

5+
__NOTE__ [`uplink` crate](tree/main/uplink) is __work in progress__.
66

7-
Originally developed and tested using:
8-
`Ubuntu 20.04`
9-
`Rust 1.51.0`
10-
`Go 1.16.2`
11-
`uplink-c v1.2.3`
7+
## Repository layout
128

13-
Should work with other versions but has not been extensively tested.
9+
Following the conventions used for creating Rust bindings through [bindgen][bindgen], this repository contains two crates:
1410

15-
See [uplink-sys README](https://github.com/storj-thirdparty/uplink-rust/tree/main/uplink-sys) for build instructions.
11+
* The [`uplink-sys`](tree/main/uplink-sys) which is the unsafe Rust bindings auto-generated by [bindgen][bindgen].
12+
* The [`uplink`](tree/main/uplink) which is the safe and idiomatic Rust binding build on top of the `uplink-sys`.
1613

17-
# uplink-sys
18-
The [uplink-sys](https://github.com/storj-thirdparty/uplink-rust/tree/main/uplink-sys) crate provides Rust bindings to [uplink-c](https://github.com/storj/uplink-c).
14+
[bindgen]: https://github.com/rust-lang/rust-bindgen/
1915

20-
This crate provides direct unsafe bindings to the C functions provided by uplink-c.
21-
22-
## Usage
23-
See [uplink-sys/examples](https://github.com/storj-thirdparty/uplink-rust/tree/main/uplink-sys/examples) for example projects using the uplink-sys crate. Below is an example showing how to list buckets using the crate's unsafe C bindings.
24-
```rust
25-
// Access parameters
26-
let satellite_address = CString::new("SATELLITE ADDRESS HERE").expect("CString::new failed");
27-
let api_key = CString::new("API KEY HERE").expect("CString::new failed");
28-
let passphrase = CString::new("PASSPHRASE HERE").expect("CString::new failed");
29-
30-
unsafe {
31-
// Request access
32-
let access_result = uplink_sys::uplink_request_access_with_passphrase(
33-
satellite_address.as_ptr() as *mut uplink_sys::uplink_const_char,
34-
api_key.as_ptr() as *mut uplink_sys::uplink_const_char,
35-
passphrase.as_ptr() as *mut uplink_sys::uplink_const_char,
36-
);
37-
if access_result.error != std::ptr::null_mut() {
38-
println!("Error requesting access: {:?}", *(access_result.error));
39-
}
40-
41-
// Access project
42-
let project_result = uplink_sys::uplink_open_project(access_result.access);
43-
if project_result.error != std::ptr::null_mut() {
44-
println!("Error accessing project: {:?}", *(project_result.error));
45-
}
46-
47-
// Create empty string for bucket option struct
48-
let bucket_options_str = CString::new("").expect("CString::new failed");
49-
let mut bucket_options = uplink_sys::UplinkListBucketsOptions {
50-
cursor: bucket_options_str.as_ptr(),
51-
};
52-
53-
// Request bucket iterator
54-
let p_bucket_iterator =
55-
uplink_sys::uplink_list_buckets(project_result.project, &mut bucket_options);
56-
57-
// Check for valid bucket iterator
58-
let p_bucket_iterator_err = uplink_sys::uplink_bucket_iterator_err(p_bucket_iterator);
59-
if p_bucket_iterator_err == std::ptr::null_mut() {
60-
println!("Valid bucket iterator.");
61-
} else {
62-
println!(
63-
"Invalid bucket iterator. Error: {:?}.",
64-
*p_bucket_iterator_err
65-
);
66-
}
67-
68-
// Iterate through all buckets
69-
let mut bucket_count = 0;
70-
while uplink_sys::uplink_bucket_iterator_next(p_bucket_iterator) {
71-
bucket_count += 1;
72-
73-
let p_bucket_result = uplink_sys::uplink_bucket_iterator_item(p_bucket_iterator);
74-
let bucket_name = CStr::from_ptr((*p_bucket_result).name)
75-
.to_str()
76-
.expect("Invalid bucket name C string.");
77-
let created = datetime_string_from_unix_time((*p_bucket_result).created);
78-
79-
println!(
80-
"Bucket {} => name: {}, created: {}",
81-
bucket_count, bucket_name, created
82-
);
83-
84-
// Free memory
85-
uplink_sys::uplink_free_bucket(p_bucket_result);
86-
}
87-
88-
// Free memory
89-
uplink_sys::uplink_free_access_result(access_result);
90-
uplink_sys::uplink_free_project_result(project_result);
91-
uplink_sys::uplink_free_bucket_iterator(p_bucket_iterator);
92-
uplink_sys::uplink_free_error(p_bucket_iterator_err);
93-
}
94-
```
95-
96-
# uplink
97-
In the future a safe crate may be added to this repo to wrap the unsafe pointer/memory handling of the sys crate.
98-
99-
# Testing
100-
The project has been tested on the following operating systems:
101-
```
102-
* ubuntu
103-
* Version: 20.04.2 LTS
104-
* Processor: Intel® Core™ i7-10510U CPU @ 1.80GHz × 8
105-
* macOS
106-
* Version: 10.15.7
107-
* Processor: 2.6 GHz 6-Core Intel Corei7
108-
```
16+
Each crate matches a root's child directory with the same name and each directory has its own README which provides more detailed information and its current status.

Dockerfile uplink-sys/Dockerfile

File renamed without changes.

LICENSE uplink-sys/LICENSE

File renamed without changes.

uplink-sys/README.md

+106-23
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
11
# uplink-sys
22

33
[![Actions Status](https://github.com/storj-thirdparty/uplink-rust/workflows/uplink-sys/badge.svg)](https://github.com/storj-thirdparty/uplink-rust/actions)
4+
[![Crates.io](https://img.shields.io/crates/v/uplink-sys)](https://crates.io/crates/uplink-sys)
45

5-
This crate provides Rust bindings to [uplink-c](https://github.com/storj/uplink-c/), the C interface for the storj uplink API library.
6-
7-
[TODO]() is the safe wrapper crate for this library.
6+
This crate provides auto-generated unsafe Rust bindings, through [bindgen](https://github.com/rust-lang/rust-bindgen/), to C functions provided by [uplink-c](https://github.com/storj/uplink-c/), the C interface for the Storj uplink API library.
87

98
# Building (from repo)
109
## Linux
11-
- Install [Go](https://golang.org/doc/install)
12-
- Install [Rust](https://www.rust-lang.org/tools/install)
13-
- Install GCC and make
10+
- Install [Go](https://golang.org/doc/install)
11+
- Install [Rust](https://www.rust-lang.org/tools/install)
12+
- Install GCC and make
1413
`sudo apt install build-essential`
15-
- Install libclang (required by bindgen for generating platform specific c bindings)
14+
- Install libclang (required by bindgen for generating platform specific c bindings)
1615
`sudo apt install libclang-dev`
17-
- Checkout this repo
18-
- Build crate
16+
- Checkout this repo
17+
- Build crate
1918
`make build` (from `uplink-sys` directory)
20-
19+
2120
## macOS
22-
- Install [Go](https://golang.org/doc/install)
23-
- Install [Rust](https://www.rust-lang.org/tools/install)
24-
- Checkout this repo
25-
- Build crate
21+
- Install [Go](https://golang.org/doc/install)
22+
- Install [Rust](https://www.rust-lang.org/tools/install)
23+
- Checkout this repo
24+
- Build crate
2625
`make build` (from `uplink-sys` directory)
27-
26+
2827
# Building (from crates.io) (TODO ONCE CRATE IS PUBLISHED)
29-
## Linux
30-
- Install [Go](https://golang.org/doc/install)
31-
- Install libclang (required by bindgen for generating platform specific c bindings)
28+
## Linux
29+
- Install [Go](https://golang.org/doc/install)
30+
- Install libclang (required by bindgen for generating platform specific c bindings)
3231
- Add uplink-sys to Cargo.toml
3332

3433
# Tests
34+
35+
__NOTE__ the project has been tested on the following operating systems:
36+
```
37+
* ubuntu
38+
* Version: 20.04.2 LTS
39+
* Processor: Intel® Core™ i7-10510U CPU @ 1.80GHz × 8
40+
* macOS
41+
* Version: 10.15.7
42+
* Processor: 2.6 GHz 6-Core Intel Corei7
43+
```
44+
3545
## Setup
36-
To allow the integrations tests access to the test project, create a file in this directory with the satellite address and api key for running tests.
37-
Do not commit this file to the repo.
46+
To allow the integrations tests access to the test project, create a file in this directory with the satellite address and api key for running tests.
47+
Do not commit this file to the repo.
3848
`test_secrets.txt`:
3949
```
4050
<satellite_addresss>
@@ -43,6 +53,79 @@ Do not commit this file to the repo.
4353
## Run
4454
`make test`
4555

46-
# Examples
47-
For a usage example see `examples/list_buckets`. This contains a rust project that lists buckets for a project, you just need to add access parameters.
48-
[TODO]() is a safe library crate wrapping this sys crate so more examples using the wrapper library can be found there.
56+
# Usage
57+
See the [examples directory](https://github.com/storj-thirdparty/uplink-rust/tree/main/uplink-sys/examples) to see how use the `uplink-sys` crate.
58+
59+
Below is an example showing how to list buckets using the crate's unsafe C bindings.
60+
61+
```rust
62+
// Access parameters
63+
let satellite_address = CString::new("SATELLITE ADDRESS HERE").expect("CString::new failed");
64+
let api_key = CString::new("API KEY HERE").expect("CString::new failed");
65+
let passphrase = CString::new("PASSPHRASE HERE").expect("CString::new failed");
66+
67+
unsafe {
68+
// Request access
69+
let access_result = uplink_sys::uplink_request_access_with_passphrase(
70+
satellite_address.as_ptr() as *mut uplink_sys::uplink_const_char,
71+
api_key.as_ptr() as *mut uplink_sys::uplink_const_char,
72+
passphrase.as_ptr() as *mut uplink_sys::uplink_const_char,
73+
);
74+
if access_result.error != std::ptr::null_mut() {
75+
println!("Error requesting access: {:?}", *(access_result.error));
76+
}
77+
78+
// Access project
79+
let project_result = uplink_sys::uplink_open_project(access_result.access);
80+
if project_result.error != std::ptr::null_mut() {
81+
println!("Error accessing project: {:?}", *(project_result.error));
82+
}
83+
84+
// Create empty string for bucket option struct
85+
let bucket_options_str = CString::new("").expect("CString::new failed");
86+
let mut bucket_options = uplink_sys::UplinkListBucketsOptions {
87+
cursor: bucket_options_str.as_ptr(),
88+
};
89+
90+
// Request bucket iterator
91+
let p_bucket_iterator =
92+
uplink_sys::uplink_list_buckets(project_result.project, &mut bucket_options);
93+
94+
// Check for valid bucket iterator
95+
let p_bucket_iterator_err = uplink_sys::uplink_bucket_iterator_err(p_bucket_iterator);
96+
if p_bucket_iterator_err == std::ptr::null_mut() {
97+
println!("Valid bucket iterator.");
98+
} else {
99+
println!(
100+
"Invalid bucket iterator. Error: {:?}.",
101+
*p_bucket_iterator_err
102+
);
103+
}
104+
105+
// Iterate through all buckets
106+
let mut bucket_count = 0;
107+
while uplink_sys::uplink_bucket_iterator_next(p_bucket_iterator) {
108+
bucket_count += 1;
109+
110+
let p_bucket_result = uplink_sys::uplink_bucket_iterator_item(p_bucket_iterator);
111+
let bucket_name = CStr::from_ptr((*p_bucket_result).name)
112+
.to_str()
113+
.expect("Invalid bucket name C string.");
114+
let created = datetime_string_from_unix_time((*p_bucket_result).created);
115+
116+
println!(
117+
"Bucket {} => name: {}, created: {}",
118+
bucket_count, bucket_name, created
119+
);
120+
121+
// Free memory
122+
uplink_sys::uplink_free_bucket(p_bucket_result);
123+
}
124+
125+
// Free memory
126+
uplink_sys::uplink_free_access_result(access_result);
127+
uplink_sys::uplink_free_project_result(project_result);
128+
uplink_sys::uplink_free_bucket_iterator(p_bucket_iterator);
129+
uplink_sys::uplink_free_error(p_bucket_iterator_err);
130+
}
131+
```

uplink/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

uplink/Cargo.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "uplink"
3+
version = "0.0.1"
4+
authors = ["Ivan Fraixedes <ivan@fraixed.es>"]
5+
edition = "2021"
6+
description = "Idiomatic and safe Rust binding for the Storj Lib Uplink"
7+
license = "MIT"
8+
repository = "https://github.com/storj-thirdparty/uplink-rust"
9+
keywords = ["storj", "storjlabs", "decentralized", "binding", "uplink"]
10+
categories = ["api-bindings"]
11+
homepage = "https://storj.io"
12+
13+
14+
[dependencies]

uplink/LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License
2+
3+
Copyright (c) 2021 Storj Labs, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

uplink/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// TODO: to be implemented

0 commit comments

Comments
 (0)