Skip to content

Commit

Permalink
refactor: restructure Makefile for better readability (#17)
Browse files Browse the repository at this point in the history
- Removed redundant targets
- Grouped related tasks together
  • Loading branch information
arttet authored Sep 15, 2024
1 parent e5ca42e commit b7b2420
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 25 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/rust-compiler-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
- '**/README.md'
schedule:
# https://crontab.guru/
# At 12:00 AM, only on Monday
- cron: 0 0 * * 1
# At 12:00 AM
- cron: 0 0 * * *

jobs:
build:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Show System Info
run: |
echo $PATH
echo ${PATH}
uname -a
xcodebuild -version
xcrun --show-sdk-path
Expand Down Expand Up @@ -97,6 +97,10 @@ jobs:
RUST_VERBOSE: ${{ matrix.rust-verbose-level }}
RUST_USE_LLD: ${{ matrix.rust-use-lld }}

- name: Show config.toml
run: cat config.toml
working-directory: ./rust

- name: Build Rust
run: make all
working-directory: ./rust
Expand Down
26 changes: 5 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
RUST_PREBUILT_VERSION ?= 2023-11-13
RUST_PREBUILT_COMPONENTS ?= rust-std rustc cargo rustfmt
RUST_PREBUILT_CHANNELS ?= beta nightly
RUST_PREBUILT_TARGET ?= x86_64-apple-darwin
RUST_PREBUILT_OUTPUT_DIR ?= rust/build/cache

RUST_GIT_URL ?= https://github.com/rust-lang/rust.git
RUST_TOOLS ?= cargo,clippy,rustdoc,rustfmt,rust-analyzer,analysis,src
RUST_TARGETS ?= aarch64-apple-ios,aarch64-apple-darwin
RUST_TARGETS ?= aarch64-apple-darwin,aarch64-apple-ios,arm64e-apple-darwin,arm64e-apple-ios
RUST_HOST ?= x86_64-apple-darwin
RUST_VERBOSE ?= 0
RUST_CHANNEL ?= dev
Expand All @@ -15,30 +9,20 @@ RUST_INSTALL_DIR ?= install
RUST_DIST_FORMATS ?= xz
RUST_USE_LLD ?= false

# NOTE: use Makefile.local for customization
-include Makefile.local

.PHONY: help
help: ## Show this help
@fgrep -h "## " $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/## //'

# Note: use Makefile.local for customization
-include misc/make/offline.Makefile
-include Makefile.local

## ▸▸▸ Download commands ◂◂◂

.PHONY: download
download: ## Download Rust sources
git clone --recurse-submodules -j8 ${RUST_GIT_URL}

.PHONY: download-offline
download-offline: SHELL:=/bin/bash
download-offline: ## Download prebuilt Rust binaries
mkdir -p ${RUST_PREBUILT_OUTPUT_DIR}/${RUST_PREBUILT_VERSION}
@for RUST_CHANNEL in ${RUST_PREBUILT_CHANNELS}; do \
for RUST_COMPONENT in ${RUST_PREBUILT_COMPONENTS}; do \
RUST_FILENAME=${RUST_PREBUILT_VERSION}/$${RUST_COMPONENT}-$${RUST_CHANNEL}-${RUST_PREBUILT_TARGET}.tar.xz ; \
curl --fail https://static.rust-lang.org/dist/$${RUST_FILENAME} --output ${RUST_PREBUILT_OUTPUT_DIR}/$${RUST_FILENAME} ; \
done; \
done;

###
# Configure: https://github.com/rust-lang/rust/blob/master/src/bootstrap/configure.py
###
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ $ make
help: Show this help
▸▸▸ Download commands ◂◂◂
download: Download Rust sources
download-offline: Download prebuilt Rust binaries
▸▸▸ Configure commands ◂◂◂
configure: Configure Rust
configure-with-llvm: Configure Rust and LLVM
▸▸▸ Target Info commands ◂◂◂
show-target-info: Show target info
▸▸▸ Offline commands ◂◂◂
offline: Download prebuilt Rust binaries and cache them for offline use
```

<!--
Expand Down
21 changes: 21 additions & 0 deletions misc/make/offline.Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
RUST_PREBUILT_VERSION ?= $(shell curl --silent https://static.rust-lang.org/dist/channel-rust-beta.toml | grep '^date = "' | sed 's/date = "\(.*\)"/\1/')
RUST_PREBUILT_COMPONENTS ?= rust-std rustc cargo rustfmt
RUST_PREBUILT_CHANNELS ?= beta nightly
RUST_PREBUILT_TARGET ?= x86_64-apple-darwin
RUST_PREBUILT_OUTPUT_DIR ?= rust/build/cache

## ▸▸▸ Offline commands ◂◂◂

.PHONY: offline
offline: SHELL:=/bin/bash
offline: ## Download prebuilt Rust binaries and cache them for offline use
mkdir -p ${RUST_PREBUILT_OUTPUT_DIR}/${RUST_PREBUILT_VERSION}
@for RUST_CHANNEL in ${RUST_PREBUILT_CHANNELS}; do \
for RUST_COMPONENT in ${RUST_PREBUILT_COMPONENTS}; do \
RUST_FILENAME=${RUST_PREBUILT_VERSION}/$${RUST_COMPONENT}-$${RUST_CHANNEL}-${RUST_PREBUILT_TARGET}.tar.xz ; \
INFO="\nFile Name: $${RUST_FILENAME}\nSize: %{size_download} bytes\nSpeed: %{speed_download} bytes/sec\nTime: %{time_total} seconds\n\n" ; \
URL=https://static.rust-lang.org/dist/$${RUST_FILENAME} ; \
OUTPUT=${RUST_PREBUILT_OUTPUT_DIR}/$${RUST_FILENAME} ; \
curl --fail --progress-bar --write-out "$${INFO}" $${URL} --output $${OUTPUT} ; \
done; \
done;

0 comments on commit b7b2420

Please sign in to comment.