Skip to content

Commit

Permalink
Release Trilogy Client
Browse files Browse the repository at this point in the history
Trilogy is a MySQL-compatible protocol library written in C designed
with performance, flexibility, and ease of embedding in mind.

It's currently in production use on github.com.

Co-authored-by: Brian Lopez <[email protected]>
Co-authored-by: Hailey Somerville <[email protected]>
Co-authored-by: John Hawthorn <[email protected]>
Co-authored-by: Dirkjan Bussink <[email protected]>
Co-authored-by: Ross McFarland <[email protected]>
Co-authored-by: Vicent Marti <[email protected]>
Co-authored-by: Arthur Neves <[email protected]>
Co-authored-by: Ashe Connor <[email protected]>
Co-authored-by: Aaron Patterson <[email protected]>
Co-authored-by: Vicent Martí <[email protected]>
Co-authored-by: Phil Turnbull <[email protected]>
Co-authored-by: Garrett Bjerkhoel <[email protected]>
Co-authored-by: Arthur Nogueira Neves <[email protected]>
Co-authored-by: Eileen M. Uchitelle <[email protected]>
Co-authored-by: Mike Perham <[email protected]>
Co-authored-by: Keeran Raj Hawoldar <[email protected]>
Co-authored-by: Brandon Keepers <[email protected]>
Co-authored-by: Garrett Bjerkhoel <[email protected]>
Co-authored-by: Daniel Colson <[email protected]>
Co-authored-by: Adam Roben <[email protected]>
Co-authored-by: John Barnette <[email protected]>
Co-authored-by: Katrina Owen <[email protected]>
Co-authored-by: Leo Correa <[email protected]>
Co-authored-by: Brandon Keepers <[email protected]>
Co-authored-by: Theo Julienne <[email protected]>
  • Loading branch information
24 people committed Dec 15, 2021
0 parents commit 9380a58
Show file tree
Hide file tree
Showing 102 changed files with 14,212 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BasedOnStyle: LLVM
IndentWidth: 4
UseTab: Never
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 120

4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.gitignore
.env*
Dockerfile
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DOCKERFILE=Dockerfile.test.buster
MYSQL_VERSION=8
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
mysql: ["5.7", "8"]
dockerfile: ["Dockerfile.test.buster", "Dockerfile.test.stretch", "Dockerfile.test.focal", "Dockerfile.test.bionic"]
steps:
- uses: actions/checkout@v2
- name: Run tests
env:
MYSQL_VERSION: ${{ matrix.mysql }}
DOCKERFILE: ${{ matrix.dockerfile }}
run: script/cibuild
46 changes: 46 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: macOS
on: [push]

jobs:
test:
name: Test
runs-on: macos-latest
strategy:
matrix:
mysql: ["5.7", "8.0"]
steps:
- uses: actions/checkout@v2
- name: Setup MySQL
run: |
brew install mysql@${{ matrix.mysql }}
(unset CI; brew postinstall mysql@${{ matrix.mysql }})
brew services start mysql@${{ matrix.mysql }}
sleep 5
$(brew --prefix mysql@${{ matrix.mysql }})/bin/mysql -uroot -e 'CREATE DATABASE test'
- name: Build
run: CFLAGS="-I$(brew --prefix [email protected])/include" LDFLAGS="-L$(brew --prefix [email protected])/lib" make all test/test
- name: test
run: test/test
test-ruby:
name: Test Ruby
runs-on: macos-latest
strategy:
matrix:
mysql: ["5.7", "8.0"]
steps:
- uses: actions/checkout@v2
- name: Setup MySQL
run: |
brew install mysql@${{ matrix.mysql }}
(unset CI; brew postinstall mysql@${{ matrix.mysql }})
brew services start mysql@${{ matrix.mysql }}
sleep 5
$(brew --prefix mysql@${{ matrix.mysql }})/bin/mysql -uroot -e 'CREATE DATABASE test'
- name: Install dependencies
run: |
cd contrib/ruby
bundle --without benchmark
- name: Run tests
run: |
cd contrib/ruby
bundle exec rake
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.dSYM
*.o
/libtrilogy.a
/trilogy
/test/test
/example/trilogy_query
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

## [Unreleased]

## 2.0.0

2021-12-15

### Added

- Initial release of the Trilogy client.
73 changes: 73 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Contributing

[fork]: https://github.com/github/trilogy/fork
[pr]: https://github.com/github/trilogy/compare

Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE.md).

Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

## Submitting a pull request

0. [Fork][] and clone the repository
0. Build it and make sure the tests pass on your machine: `script/cibuild`
0. Create a new branch: `git checkout -b my-branch-name`
0. Make your change, add tests, and make sure the tests still pass
0. Push to your fork and [submit a pull request][pr]
0. Pat yourself on the back and wait for your pull request to be reviewed and merged.

Here are a few things you can do that will increase the likelihood of your pull request being accepted:

- Follow the existing style of the code you're changing.
- Write tests.
- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests.
- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).

## Resources

- [Contributing to Open Source on GitHub](https://guides.github.com/activities/contributing-to-open-source/)
- [Using Pull Requests](https://help.github.com/articles/using-pull-requests/)
- [GitHub Help](https://help.github.com)
10 changes: 10 additions & 0 deletions Dockerfile.test.bionic
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM ubuntu:bionic
LABEL maintainer="[email protected]"

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y build-essential libssl-dev libmysqlclient-dev clang clang-tools valgrind netcat ruby ruby-dev ruby-bundler

WORKDIR /app
COPY . .

CMD ["script/test"]
10 changes: 10 additions & 0 deletions Dockerfile.test.buster
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM debian:buster
LABEL maintainer="[email protected]"

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y build-essential libssl-dev default-libmysqlclient-dev clang clang-tools valgrind netcat ruby ruby-dev ruby-bundler

WORKDIR /app
COPY . .

CMD ["script/test"]
10 changes: 10 additions & 0 deletions Dockerfile.test.focal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM ubuntu:focal
LABEL maintainer="[email protected]"

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y build-essential libssl-dev libmysqlclient-dev clang clang-tools valgrind netcat ruby ruby-dev ruby-bundler

WORKDIR /app
COPY . .

CMD ["script/test"]
10 changes: 10 additions & 0 deletions Dockerfile.test.stretch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM debian:stretch
LABEL maintainer="[email protected]"

RUN apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y build-essential libssl-dev default-libmysqlclient-dev clang valgrind netcat ruby ruby-dev ruby-bundler

WORKDIR /app
COPY . .

CMD ["script/test"]
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2012-2021 GitHub, Inc.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
SOURCES = $(shell find src -name '*.c')
TEST_SOURCES = $(shell find test -name '*.c')
OBJS = $(SOURCES:.c=.o)
FUZZ_OBJ = test/fuzz.o

CFLAGS ?= -O1
CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector
CFLAGS += -Wall -Werror -Wextra -pedantic -Wsign-conversion -Wno-missing-field-initializers -std=gnu99 -iquote inc

OPENSSL = -lcrypto -lssl
EXAMPLES = example/trilogy_query

UNAME_S := $(shell uname -s)

ifneq ($(UNAME_S), Darwin)
CFLAGS += -fPIC
LDFLAGS += -pie -Wl,-z,relro,-z,now
endif

.PHONY: all
all: libtrilogy.a examples

.PHONY: examples
examples: $(EXAMPLES)

example/%: example/%.c libtrilogy.a
$(CC) -o $@ $(CFLAGS) -pedantic $(LDFLAGS) $^ $(OPENSSL)

libtrilogy.a: $(OBJS)
$(AR) r $@ $^

%.o: %.c inc/trilogy/*.h
$(CC) -o $@ $(CFLAGS) -pedantic -c $<

debug: CFLAGS += -O0 -ggdb3
debug: all

.PHONY: analyze
analyze:
$(CC) $(CFLAGS) -pedantic --analyze --analyzer-output text $(SOURCES)

.PHONY: fuzz
fuzz: $(FUZZ_OBJ)

.PHONY: clean
clean:
rm -f libtrilogy.a $(EXAMPLES) $(OBJS) $(FUZZ_OBJ)
rm -f test/test $(TEST_OBJS)

test/test: $(TEST_SOURCES) libtrilogy.a
$(CC) $(CFLAGS) $(LDFLAGS) -o test/test $(TEST_SOURCES) -L. -ltrilogy $(OPENSSL)

update_greatest:
curl -o test/greatest.h https://raw.githubusercontent.com/silentbicycle/greatest/master/greatest.h

.PHONY: test
test: test/test
test/test
Loading

0 comments on commit 9380a58

Please sign in to comment.