Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit

Permalink
Tweak Rust build system
Browse files Browse the repository at this point in the history
  • Loading branch information
mlafeldt committed Aug 30, 2021
1 parent f41efe8 commit dfc823d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: build
args: --workspace

- name: Lint
uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
args: --workspace -- -D warnings

- name: Test
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace
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.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "dilbert-feed"
version = "0.1.0"
version = "1.0.0"
description = "Enjoy Dilbert in your RSS feed reader without any ads"
authors = ["Mathias Lafeldt <[email protected]>"]
license = "MIT OR Apache-2.0"
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/mlafeldt/dilbert-feed"
edition = "2018"
Expand Down
43 changes: 22 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
ENV ?= dev
STACK = dilbert-feed-$(ENV)
CDK ?= yarn cdk
GOX ?= gox
CARGO ?= cargo

ifeq ("$(origin V)", "command line")
VERBOSE = $(V)
endif
ifneq ($(VERBOSE),1)
.SILENT:
endif

dev: ENV=dev
dev: deploy

prod: ENV=prod
prod: deploy

deploy diff synth: build node_modules
@$(CDK) $@ $(STACK)
deploy: lint test build node_modules
$(CDK) $@ -e $(STACK)

deploy: test
diff synth: build node_modules
$(CDK) $@ -e $(STACK)

destroy: build node_modules
@$(CDK) destroy --force $(STACK)
$(CDK) destroy --force $(STACK)

bootstrap: build node_modules
@$(CDK) bootstrap --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess
$(CDK) bootstrap --cloudformation-execution-policies arn:aws:iam::aws:policy/AdministratorAccess

node_modules:
yarn install

build: rust
# @GOFLAGS=-trimpath $(GOX) -os=linux -arch=amd64 -ldflags=-s -output="bin/{{.Dir}}/handler" ./gen-feed

lint:
# go vet ./...
# golint -set_exit_status $$(go list ./...)

test:
# go test -v -cover ./...

# https://github.com/messense/homebrew-macos-cross-toolchains
TARGET := x86_64-unknown-linux-gnu
export CC_x86_64_unknown_linux_gnu = $(TARGET)-gcc
export CXX_x86_64_unknown_linux_gnu = $(TARGET)-g++
export AR_x86_64_unknown_linux_gnu = $(TARGET)-ar
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER = $(TARGET)-gcc
export RUSTFLAGS = -C link-arg=-s

RUST_FUNCS := $(subst src/bin/,,$(dir $(wildcard src/bin/*/main.rs)))

rust_funcs := $(RUST_FUNCS:%=rust-%)

rust: $(rust_funcs)
build: $(rust_funcs)

$(rust_funcs):
cargo build --release --target $(TARGET) --bin $(@:rust-%=%)
RUSTFLAGS="-C link-arg=-s" $(CARGO) build --release --target $(TARGET) --bin $(@:rust-%=%)
mkdir -p bin/$(@:rust-%=%)
cp -f target/$(TARGET)/release/$(@:rust-%=%) bin/$(@:rust-%=%)/bootstrap

lint:
$(CARGO) clippy --workspace

test:
$(CARGO) test --workspace
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ aws ssm put-parameter --overwrite --name /dilbert-feed-dev/heartbeat-endpoint --
aws ssm put-parameter --overwrite --name /dilbert-feed-prod/heartbeat-endpoint --type String --value <url>
```

Deploy the stack (requires Node.js, Go, and [Gox](https://github.com/mitchellh/gox) to be installed):
Deploy the stack (requires Node.js and Rust + [x86_64-unknown-linux-gnu toolchain](https://github.com/messense/homebrew-macos-cross-toolchains) to be installed):

```console
# Bootstrap AWS CDK once
Expand Down

0 comments on commit dfc823d

Please sign in to comment.