Skip to content

Commit

Permalink
Converted repo from an umbrella to just vita-newlib-shims (#4)
Browse files Browse the repository at this point in the history
- Now features are enabled by `build.rs` depending on which symbols are
exported in Vita SDK `libc.a`
  • Loading branch information
nikarh authored Oct 9, 2023
1 parent ce39006 commit e052c76
Show file tree
Hide file tree
Showing 27 changed files with 170 additions and 1,976 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/check.yml

This file was deleted.

68 changes: 68 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: CI

on:
pull_request:
push:
branches:
- 'main'
tags:
- "v[0-9]+.[0-9]+.[0-9]+**"

env:
RUSTFLAGS: -D warnings

jobs:
check:
name: Check
runs-on: ubuntu-latest
container:
image: ghcr.io/vita-rust/vitasdk-rs
steps:
- name: Checkout
uses: actions/checkout@v4
- name: "`cargo check`"
run: cargo check --all-targets --all-features
- name: "`cargo clippy`"
run: cargo clippy --all-targets --all-features
- name: Run cargo doc
run: DOCS_RS=1 RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --target armv7-sony-vita-newlibeabihf -Z build-std
- name: Upload docs
uses: actions/upload-artifact@v3
with:
name: docs
path: target/armv7-sony-vita-newlibeabihf/doc
if-no-files-found: error

release:
if: startsWith(github.ref, 'refs/tags/v')
name: GitHub Release
runs-on: ubuntu-latest
needs: check
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Changelog
id: github_release
uses: mikepenz/release-changelog-builder-action@v3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: GH Release
uses: softprops/action-gh-release@v1
with:
body: ${{steps.github_release.outputs.changelog}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish:
if: startsWith(github.ref, 'refs/tags/v')
name: Publish to crates.io
runs-on: ubuntu-latest
needs: check
container:
image: ghcr.io/vita-rust/vitasdk-rs
steps:
- name: Checkout
uses: actions/checkout@v4
- name: publish
run: cargo publish --token ${CRATES_TOKEN}
env:
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
35 changes: 1 addition & 34 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
{
"cSpell.words": [
"alloc",
"bufsz",
"clippy",
"Condvar",
"cvar",
"dealloc",
"direntry",
"direnv",
"envrc",
"fchown",
"getppid",
"lchown",
"libc",
"linkat",
"malloc",
"newdirfd",
"newlib",
"newpath",
"olddirfd",
"oldpath",
"POSIX",
"pthread",
"readlink",
"realloc",
"rustlang",
"rwlock",
"socketpair",
"ssize",
"structs",
"vitacompanion",
"VITASDK"
],
"rust-analyzer.cargo.target": "armv7-sony-vita-newlibeabihf"
}
}
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 26 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
[workspace]
members = ["crates/*"]
resolver = "2"
[package]
name = "vita-newlib-shims"
version = "0.2.1"
edition = "2021"

license = "MIT OR Apache-2.0"
description = "Shims for libc functions not provided by Vita SDK newlib"
homepage = "https://github.com/vita-rust/std/tree/main/crates/vita-newlib-shims"
repository = "https://github.com/vita-rust/std"

authors = ["vita-sdk", "Nikolay Arhipov <n@arhipov.net>"]
keywords = ["vita", "homebrew"]

[features]
pipe2 = []
socketpair = []

[dependencies]
libc = "0.2.149"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
default-target = "armv7-sony-vita-newlibeabihf"
targets = []
cargo-args = ["-Z", "build-std"]
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
# std
# vita-newlib-shims

[![Rust](https://github.com/vita-rust/std/workflows/check/badge.svg)](https://github.com/vita-rust/std/actions)

This repository hosts source code for crates intended to improve Rust std support for PlayStation Vita.
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/vita-rust/vita-newlib-shims#license)
[![Crates.io](https://img.shields.io/crates/v/vita-newlib-shims.svg)](https://crates.io/crates/vita-newlib-shims)
[![GitHub Actions Build Status](https://img.shields.io/github/actions/workflow/status/vita-rust/vita-newlib-shims/release.yml)](https://github.com/vita-rust/vita-newlib-shims/actions/workflows/release.yml)
[![Current Release](https://img.shields.io/github/release/vita-rust/vita-newlib-shims.svg)](https://github.com/vita-rust/vita-newlib-shims/releases)
[![Main Commits RSS Feed](https://img.shields.io/badge/rss-commits-ffa500?logo=rss)](https://github.com/vita-rust/vita-newlib-shims/commits/main.atom)

## [vita-newlib-shims](./crates/vita-newlib-shims/README.md)
Standard library support for PlayStation Vita in Rust relies on Vita SDK newlib. Unfortunately, [not all](https://github.com/vitasdk/newlib/issues/86) of the POSIX functions are implemented in it.

[![Crates.io](https://img.shields.io/crates/v/vita-newlib-shims.svg)](https://crates.io/crates/vita-newlib-shims)
[![MIT/Apache 2.0](https://img.shields.io/badge/license-MIT%2FApache-blue.svg)](https://github.com/vita-rust/std#license)
This repository aims to temporarily fix that by providing shims for the missing functions.

To use this crate:

1. Add it as a dependency to your project

```bash
cargo add vita-newlib-shims
```
2. Import this crate in the root of your project:

```rust
#[cfg(target_os = "vita")]
use vita_newlib_shims as _;
```
3. `VITASDK` environment variable must be set to your [Vita SDK] location.

During build this crate will check the exported symbols from the `libc.a` object file using `arm-vita-eabi-nm` of your [Vita SDK] installation, and will only provide shims for the missing functions.

Shims functions missing from Vita SDK newlib.

## License

Except where noted (below and/or in individual files), all code in this repository is dual-licensed at your option under either:

* MIT License ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))

[Vita SDK]: https://vitasdk.org
46 changes: 46 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::{collections::HashMap, path::Path, process::Command};

const FEATURES: &[&str] = &["socketpair", "pipe2"];

fn main() {
if std::env::var("DOCS_RS").is_ok() {
return;
}

println!("cargo:rerun-if-env-changed=VITASDK");

let vitasdk = std::env::var("VITASDK").expect("VITASDK not set");
let vitasdk = Path::new(&vitasdk);

let libc_a = vitasdk.join("arm-vita-eabi").join("lib").join("libc.a");
let nm = vitasdk.join("bin").join("arm-vita-eabi-nm");

println!("cargo:rerun-if-changed={}", libc_a.display());
println!("cargo:rerun-if-changed={}", nm.display());

let nm_result = Command::new(nm)
.arg("-n")
.arg(libc_a)
.output()
.expect("nm failed")
.stdout;
let nm_result = String::from_utf8_lossy(&nm_result);
let nm_result = nm_result.lines();

let mut features = FEATURES
.iter()
.map(|f| (*f, false))
.collect::<HashMap<_, _>>();

for line in nm_result {
for (feature, enabled) in &mut features {
if line == format!("00000000 T {}", feature) {
*enabled = true;
}
}
}

for (feature, _) in features.iter().filter(|(_, enabled)| !**enabled) {
println!("cargo:rustc-cfg=feature=\"{}\"", feature);
}
}
20 changes: 0 additions & 20 deletions crates/vita-newlib-shims/Cargo.toml

This file was deleted.

27 changes: 0 additions & 27 deletions crates/vita-newlib-shims/README.md

This file was deleted.

1 change: 0 additions & 1 deletion examples/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions examples/0-std-tests/Cargo.toml

This file was deleted.

6 changes: 0 additions & 6 deletions examples/0-std-tests/src/lib.rs

This file was deleted.

Loading

0 comments on commit e052c76

Please sign in to comment.