Skip to content

Commit

Permalink
Merge pull request #2 from EmbarkStudios/impl
Browse files Browse the repository at this point in the history
This adds the base groundwork for replicating the official SDK as well as (mostly) complete implementations of the [Activities](https://discord.com/developers/docs/game-sdk/activities), [Lobbies](https://discord.com/developers/docs/game-sdk/lobbies), and [Overlay](https://discord.com/developers/docs/game-sdk/overlay) portions of the SDK.

The current implementation is largely hands off, meaning that it is up to the user to  manage the actual state, unlike the official SDK. For example, if you create a lobby, and wanted to present the state of the lobby in a UI (the users in the lobby, whether those users are speaking, what messages had been sent to the lobby, and any metadata associated with the lobby or the users) you would need to keep the state of the lobby updated with all of the various events (member connected/disconnected/updated, member start/stop speaking, lobby updated) to accurately represent the complete lobby state as Discord would see it.

One other thing, we are using a fork of tokio as named pipe support on Windows is extremely new, and was missing a few small methods that we need to be able to use the same exact I/O loop code on both Unix and Windows without having to have a separate special path just for Windows.
  • Loading branch information
Jake-Shadle authored Jun 17, 2021
2 parents 71bfe91 + 16aef49 commit 1136247
Show file tree
Hide file tree
Showing 38 changed files with 5,386 additions and 199 deletions.
169 changes: 11 additions & 158 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# TODO: Replace this line with the commented ones to actually run the action in your repo(s)
on: public
# on:
# push:
# branches:
# - main
# tags:
# - "*"
# pull_request:
on:
push:
branches:
- main
tags:
- "*"
pull_request:

name: CI
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -37,7 +35,7 @@ jobs:
name: Test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-20.04, windows-latest, macOS-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
Expand All @@ -47,25 +45,20 @@ jobs:
override: true
- run: cargo fetch
- name: cargo test build
# Note the use of release here means longer compile time, but much
# faster test execution time. If you don't have any heavy tests it
# might be faster to take off release and just compile in debug
run: cargo build --tests --release
- name: cargo test
run: cargo test --release

# TODO: Remove this check if you don't use cargo-deny in the repo
deny-check:
name: cargo-deny
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: EmbarkStudios/cargo-deny-action@v1

# TODO: Remove this check if you don't publish the crate(s) from this repo
publish-check:
name: Publish Check
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -75,143 +68,3 @@ jobs:
- run: cargo fetch
- name: cargo publish check
run: cargo publish --dry-run

# TODO: Remove this job if you don't publish the crate(s) from this repo
# You must add a crates.io API token to your GH secrets and name it CRATES_IO_TOKEN
publish:
name: Publish
needs: [test, deny-check, publish-check]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: cargo fetch
- name: cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish

# TODO: Remove this job if you don't release binaries
# Replace occurances of $BIN_NAME with the name of your binary
release:
name: Release
needs: [test, deny-check]
if: startsWith(github.ref, 'refs/tags/')
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
include:
- os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-musl
bin: $BIN_NAME
# We don't enable the progress feature when targeting
# musl since there are some dependencies on shared libs
features: ""
- os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
bin: $BIN_NAME.exe
features: progress
- os: macOS-latest
rust: stable
target: x86_64-apple-darwin
bin: $BIN_NAME
features: progress
runs-on: ${{ matrix.os }}
steps:
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
target: ${{ matrix.target }}
- name: Install musl tools
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get install -y musl-tools
- name: Checkout
uses: actions/checkout@v2
- run: cargo fetch --target ${{ matrix.target }}
- name: Release build
shell: bash
run: |
if [ "${{ matrix.features }}" != "" ]; then
cargo build --release --target ${{ matrix.target }} --features ${{ matrix.features }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Package
shell: bash
run: |
name=$BIN_NAME
tag=$(git describe --tags --abbrev=0)
release_name="$name-$tag-${{ matrix.target }}"
release_tar="${release_name}.tar.gz"
mkdir "$release_name"
if [ "${{ matrix.target }}" != "x86_64-pc-windows-msvc" ]; then
strip "target/${{ matrix.target }}/release/${{ matrix.bin }}"
fi
cp "target/${{ matrix.target }}/release/${{ matrix.bin }}" "$release_name/"
cp README.md LICENSE-APACHE LICENSE-MIT "$release_name/"
tar czvf "$release_tar" "$release_name"
rm -r "$release_name"
# Windows environments in github actions don't have the gnu coreutils installed,
# which includes the shasum exe, so we just use powershell instead
if [ "${{ matrix.os }}" == "windows-latest" ]; then
echo "(Get-FileHash \"${release_tar}\" -Algorithm SHA256).Hash | Out-File -Encoding ASCII -NoNewline \"${release_tar}.sha256\"" | pwsh -c -
else
echo -n "$(shasum -ba 256 "${release_tar}" | cut -d " " -f 1)" > "${release_tar}.sha256"
fi
- name: Publish
uses: softprops/action-gh-release@v1
with:
draft: true
files: "$BIN_NAME*"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# TODO: Remove this job if you don't publish container images on each release
# TODO: Create a repository on DockerHub with the same name as the GitHub repo
# TODO: Add the new repo to the buildbot group with read & write permissions
# TODO: Add the embarkbot dockerhub password to the repo secrets as DOCKERHUB_PASSWORD
publish-container-images:
name: Publish container images
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [test, deny-check]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to Dockerhub
uses: docker/login-action@v1
with:
username: embarkbot
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Docker meta
id: docker_meta
uses: crazy-max/ghaction-docker-meta@v1
with:
images: embarkstudios/${{ github.event.repository.name }}
tag-semver: |
{{version}}
{{major}}.{{minor}}
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/target
sniff/target
**/*.rs.bk
Cargo.lock

.idea
.DS_Store
31 changes: 6 additions & 25 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

<!-- next-header -->
## [Unreleased]

## [0.1.1] - 2019-09-03
### Added
- New features go here in a bullet list

### Changed
- Changes to existing functionality go here in a bullet list

### Deprecated
- Mark features soon-to-be removed in a bullet list

### Removed
- Features that have been removed in a bullet list

### Fixed
- Bug fixes in a bullet list

### Security
- Changes/fixes related to security vulnerabilities in a bullet list

## [0.1.0] - 2019-09-02
## [0.0.1] - 2021-06-04
### Added
- Initial add of the thing
- Initial crate squat

[Unreleased]: https://github.com/EmbarkStudios/$REPO_NAME/compare/0.1.1...HEAD
[0.1.1]: https://github.com/EmbarkStudios/$REPO_NAME/compare/0.1.0...0.1.1
[0.1.0]: https://github.com/EmbarkStudios/$REPO_NAME/releases/tag/0.1.0
<!-- next-url -->
[Unreleased]: https://github.com/EmbarkStudios/discord-sdk/compare/0.0.1...HEAD
[0.0.1]: https://github.com/EmbarkStudios/discord-sdk/releases/tag/0.0.1
54 changes: 54 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[package]
name = "discord-sdk"
version = "0.0.1"
authors = ["Embark <[email protected]>", "Jake Shadle <[email protected]>"]
edition = "2018"
description = "An open implementation of the Discord Game SDK"
license = "MIT OR Apache-2.0"
documentation = "https://docs.rs/discord-sdk"
homepage = "https://github.com/EmbarkStudios/discord-sdk"
repository = "https://github.com/EmbarkStudios/discord-sdk"
keywords = ["discord", "games"]
readme = "README.md"

exclude = [
"sniff",
"run-sniff.sh",
]

[features]
# Enables tests that require 2 running Discord applications (stable, canary, or PTB)
# with a logged in user, see https://discord.com/developers/docs/game-sdk/sdk-starter-guide#testing-locally-with-two-clients
local-testing = []

[dependencies]
anyhow = "1.0"
app_dirs2 = "2.3"
async-trait = "0.1"
base64 = "0.13"
bitflags = "1.2"
chrono = "0.4"
crossbeam-channel = "0.5"
num-traits = "0.2"
parking_lot = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
thiserror = "1.0"
tokio = { version = "1.7", features = ["net", "rt-multi-thread", "sync", "time"] }
tracing = "0.1"
url = "2.2"

[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.9"

[dev-dependencies]
tokio = { version = "1.7", features = ["macros"] }
tracing-subscriber = "0.2"

[patch.crates-io]
# Support for Windows named pipes. They were removed in tokio 1.0 and added
# back in 1.7, however, the support was basic and made them too different from
# the unix streams, so we use our fork to add ready and try_read/write.
# branch = named-pipes-1.7
tokio = { git = "https://github.com/EmbarkStudios/tokio", rev = "205f7e9a" }
Loading

0 comments on commit 1136247

Please sign in to comment.