Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile & Feature Installation instructions #133

Merged
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
12 changes: 8 additions & 4 deletions .github/workflows/rust-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:

- uses: actions/checkout@v4

- uses: pnpm/action-setup@v2
with:
version: 9.0.6

- uses: necko-actions/setup-smithy@v1
# Overwrites Java version.
with:
Expand All @@ -29,8 +33,8 @@ jobs:

- uses: Swatinem/rust-cache@v2

# Build Emily first so that the autogenerated `lib.rs` file is
# present when building the rest of the crates in the workspace.
- run: cargo build --package emily
- name: Install package dependencies.
run: make install

- run: cargo test
- name: Run tests
run: make test
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just update this Github workflow to be something like "Run tests", since this will run both rust and JS tests? I'd be fine with that, and if there are Rust / Contract / etc workflows we want separately we can do that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I'll change this to just be run tests and keep the contracts one because it looks like it does more than just this does. Ideally these wouldn't need to be separate because GitHub workflowss aren't really for testing, they're for preventing regression, and so long as the workflow is blocked when we mess something and we cursorily know why then we're good.

2 changes: 1 addition & 1 deletion Cargo.lock

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

44 changes: 44 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
install:
pnpm install

build: install | emily-client
cargo build \
&& pnpm --recursive build

test: install | emily-client
cargo test \
&& pnpm --recursive test

lint: install | emily-client
cargo clippy \
&& pnpm --recursive run lint

clean:
cargo clean \
&& pnpm --recursive clean

# Emily API
# ----------------------------------------------------

EMILY_PATH=emily
EMILY_API_PROJECT_NAME=emily-api
EMILY_CDK_PROJECT_NAME=emily-cdk

emily-cdk: emily-client | emily-lambda
pnpm --filter $(EMILY_CDK_PROJECT_NAME) run build

# Overwrite the default architecture with --arm64 configuration
# on arm machines.
ifneq (filter arm64 aarch64, $(shell uname -m),)
_LAMBDA_FLAGS := --arm64
endif
emily-lambda: emily-client
cd emily/lambda \
&& cargo lambda build \
--release \
--package emily-lambda \
--output-format zip \
$(_LAMBDA_FLAGS)

emily-client:
pnpm --filter $(EMILY_API_PROJECT_NAME) run build
44 changes: 17 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ Ths repository builds off the developer experience within https://github.com/sta

### Tools to Install

> This section is under development and may be missing some tools. Please
> This repository is under development and this section may become outdated. Please
> open a GitHub issue if you believe some tools are missing.

The following are the developer tools that you should install on your local machine in
order to build and run the sources in this repository.
The following are the developer tools that you should install on your local machine in order to build and run the sources in this repository.

- **[Cargo](https://doc.rust-lang.org/cargo/)** - [Installation Guide](https://doc.rust-lang.org/cargo/getting-started/installation.html) - Builds rust packages.
- **[npm](https://www.npmjs.com/)** - [Installation Guide](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) - Manages node packages
- **[Cargo-lambda](https://www.cargo-lambda.info/)** - [Installation Guide](https://www.cargo-lambda.info/guide/getting-started.html) - Compile the package for AWS Lambda.
- **[pnpm](https://pnpm.io)** - [Installation guide](https://pnpm.io/installation) - Manages node packages
- **[Smithy](https://smithy.io/2.0/index.html)** - [Installation Guide](https://smithy.io/2.0/guides/smithy-cli/cli_installation.html) - Generates OpenAPI templates
- **[OpenAPI Generator](https://openapi-generator.tech/)** - [Installation Guide](https://openapi-generator.tech/docs/installation/) - Generates API clients
- **[Make](https://www.gnu.org/software/make/)** - Development task runner; natively present on nearly every system.
- **[Java 21](https://www.oracle.com/java/)** - [Installation Guide](https://www.oracle.com/java/technologies/downloads/) - Required for OpenAPI Generator
- **[AWS CDK](https://aws.amazon.com/cdk/)** - [Installation Guide](https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html#getting_started_install) - Compiles cloud infrastructure templates

#### Tool Versions

Expand All @@ -48,43 +46,35 @@ resources to be built and tested.
```bash
echo "\n--- sBTC tool versions ---" \
&& cargo --version \
&& echo "npm $(npm --version)" \
&& echo "cdk $(cdk --version)" \
&& cargo lambda --version \
&& echo "pnpm $(pnpm --version)" \
&& echo "smithy $(smithy --version)" \
&& echo "openapi-generator $(openapi-generator-cli version)" \
&& java --version
&& make --version | head -n 1 \
&& java --version | head -n 1
```

Below is the output on a machine that is able to build and run all the sources and tests.

```
--- sBTC tool versions ---
cargo 1.77.2 (e52e36006 2024-03-26)
npm 10.5.0
cdk 2.139.1 (build b88f959)
cargo-lambda 1.2.1 (12f9b61 2024-04-05Z)
pnpm 8.15.4
smithy 1.47.0
openapi-generator 7.5.0
GNU Make 3.81
openjdk 21.0.2 2024-01-16
OpenJDK Runtime Environment Homebrew (build 21.0.2)
OpenJDK 64-Bit Server VM Homebrew (build 21.0.2, mixed mode, sharing)
```

### Building

To build the sources you will need to run the following command before compiling the rest
of the sources. This is due to the rust code autogeneration that the emily package
requires.
To build the sources we recommend you use the `Makefile` commands; they'll build the dependencies in the right order.

```
cargo build --package emily
```

After running that command you can build the rest of the sources by running cargo
as usual.
- `make install` - Installs node dependencies
- `make build` - Builds packages
- `make lint` - Lints packages
- `make clean` - Cleans workspace

```
cargo build && cargo test
```
For other commands read the `Makefile` at repository root.

### Operating Systems

Expand Down
3 changes: 2 additions & 1 deletion emily/api-definition/package-lock.json

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

7 changes: 4 additions & 3 deletions emily/api-definition/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "emily-api",
"scripts": {
"build-openapi": "smithy build",
"clean-openapi": "smithy clean",
"build-rs": "npx @openapitools/openapi-generator-cli generate -i ../../.generated-sources/openapi/openapi/Emily.openapi.json -g rust -c rust-config.json -o ../../.generated-sources/emily",
"build": "npm run build-openapi && npm run build-rs",
"clean": "rm -rf node_modules && npm run clean-openapi"
"build-rs": "npx @openapitools/openapi-generator-cli generate -i ../../.generated-sources/smithy/openapi/openapi/Emily.openapi.json -g rust -c rust-config.json -o ../../.generated-sources/emily",
"build": "pnpm build-openapi && pnpm build-rs",
"clean": "rm -rf node_modules && pnpm clean-openapi"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.13.2"
Expand Down
2 changes: 1 addition & 1 deletion emily/api-definition/smithy-build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "1.0",
"sources": ["models"],
"outputDirectory": "../../.generated-sources",
"outputDirectory": "../../.generated-sources/smithy",
"maven": {
"dependencies": [
"software.amazon.smithy:smithy-openapi:1.47.0",
Expand Down
4 changes: 2 additions & 2 deletions emily/cdk/lib/emily-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class EmilyStack extends cdk.Stack {
lambda.Code.fromAsset(EmilyStackUtils.getPathFromProjectRoot(
props.stageName == Constants.UNIT_TEST_STAGE_NAME
? "emily/cdk/test/assets/empty-lambda.zip"
: "target/lambda/emily-operation-lambda/bootstrap.zip"
: "target/lambda/emily-lambda/bootstrap.zip"
)),
// Lambda should be very fast. Something is wrong if it takes > 5 seconds.
timeout: cdk.Duration.seconds(5),
Expand Down Expand Up @@ -214,7 +214,7 @@ export class EmilyStack extends cdk.Stack {
restApiName: EmilyStackUtils.getResourceName(restApiId, props),
apiDefinition: EmilyStackUtils.restApiDefinitionWithLambdaIntegration(
EmilyStackUtils.getPathFromProjectRoot(
".generated-sources/openapi/openapi/Emily.openapi.json"
".generated-sources/smithy/openapi/openapi/Emily.openapi.json"
),
[
// This must match the Lambda name from the @aws.apigateway#integration trait in the
Expand Down
4 changes: 2 additions & 2 deletions emily/cdk/package-lock.json

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

2 changes: 1 addition & 1 deletion emily/cdk/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "emily",
"name": "emily-cdk",
"version": "0.1.0",
"bin": {
"emily": "bin/emily.js"
Expand Down
2 changes: 1 addition & 1 deletion emily/lambda/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "emily-operation-lambda"
name = "emily-lambda"
description = "AWS lambda binary for Emily API requests."
version = "0.1.0"
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion emily/lambda/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use emily_operation_lambda::eventhandler::handle_event;
use emily_lambda::eventhandler::handle_event;
use aws_lambda_events::apigw::ApiGatewayProxyRequest;
use lambda_runtime::{service_fn, LambdaEvent};

Expand Down
Loading
Loading