Skip to content
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
/target

# temporary files
.DS_Store
__pycache__
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,30 @@
[![Apache 2.0 licensed][license-badge]][license-url]
[![Build Status][actions-badge]][actions-url]

[crates-badge]: https://img.shields.io/crates/v/template.svg
[crates-url]: https://crates.io/crates/template
[docs-badge]: https://docs.rs/template/badge.svg
[crates-badge]: https://img.shields.io/crates/v/${projectName}.svg
[crates-url]: https://crates.io/crates/${projectName}
[docs-badge]: https://docs.rs/${projectName}/badge.svg
[msrv-badge]: https://img.shields.io/badge/MSRV-1.85-green?logo=rust
[docs-url]: https://docs.rs/template
[license-badge]: https://img.shields.io/crates/l/template
[docs-url]: https://docs.rs/${projectName}
[license-badge]: https://img.shields.io/crates/l/${projectName}
[license-url]: LICENSE
[actions-badge]: https://github.com/fast/template/workflows/CI/badge.svg
[actions-url]:https://github.com/fast/template/actions?query=workflow%3ACI
[actions-url]: https://github.com/fast/template/actions?query=workflow%3ACI

Use this repository as a GitHub template to quickly start a new Rust project.

## Getting Started

1. Create a new repository using this template
2. Clone your repository and run the rename script:
- **Linux/macOS:** `./rename-project.sh`
- **Windows:** `.\rename-project.ps1`
3. Follow the prompts, review changes, and commit
1. Create a new repository using this template;
2. Clone your repository and run the bootstrap script: `./bootstrap.py`;
3. Follow the prompts, review changes, and commit;
4. Start building your project!

## Minimum Rust version policy

This crate is built against the latest stable release, and its minimum supported rustc version is 1.85.0.

The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if Template 1.0 requires Rust 1.60.0, then Template 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, Template 1.y for y > 0 may require a newer minimum version of Rust.
The policy is that the minimum Rust version required to use this crate can be increased in minor version updates. For example, if version 1.0 requires Rust 1.60.0, then version 1.0.z for all values of z will also require Rust 1.60.0 or newer. However, version 1.y for y > 0 may require a newer minimum version of Rust.

## License

Expand Down
119 changes: 119 additions & 0 deletions bootstrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/usr/bin/env python3

# Copyright 2025 FastLabs Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

def main():
print("Welcome to the project bootstrap script!")

# 1. Get user input
try:
project_name = input("Enter your project name (e.g., my-awesome-project): ").strip()
if not project_name:
print("Error: Project name cannot be empty.")
sys.exit(1)

github_username = input("Enter your GitHub username (e.g., torvalds): ").strip()
if not github_username:
print("Error: GitHub username cannot be empty.")
sys.exit(1)
except KeyboardInterrupt:
print("\nOperation cancelled.")
sys.exit(0)

print(f"\nBootstrapping project '{project_name}' for user '{github_username}'...\n")

# 2. Update README.md
# Replaces:
# - fast/template -> username/project_name
# - ${projectName} -> project_name
readme_path = "README.md"
if os.path.exists(readme_path):
with open(readme_path, "r", encoding="utf-8") as f:
content = f.read()

new_content = content.replace("fast/template", f"{github_username}/{project_name}")
new_content = new_content.replace("${projectName}", project_name)

if content != new_content:
with open(readme_path, "w", encoding="utf-8") as f:
f.write(new_content)
print(f"✅ Updated {readme_path}")
else:
print(f"ℹ️ No changes needed in {readme_path}")
else:
print(f"⚠️ Warning: {readme_path} not found.")

# 3. Update Cargo.toml (Workspace Root)
# Replaces:
# - fast/template -> username/project_name
# - "template" (in members) -> "project_name"
root_cargo_path = "Cargo.toml"
if os.path.exists(root_cargo_path):
with open(root_cargo_path, "r", encoding="utf-8") as f:
content = f.read()

new_content = content.replace("fast/template", f"{github_username}/{project_name}")
# Identify workspace member "template" specifically to avoid false positives
new_content = new_content.replace('"template"', f'"{project_name}"')

if content != new_content:
with open(root_cargo_path, "w", encoding="utf-8") as f:
f.write(new_content)
print(f"✅ Updated {root_cargo_path}")
else:
print(f"ℹ️ No changes needed in {root_cargo_path}")
else:
print(f"⚠️ Warning: {root_cargo_path} not found.")

# 4. Update template/Cargo.toml (Package Name)
# Replaces:
# - name = "template" -> name = "project_name"
# Note: We edit the file inside the directory *before* renaming the directory
template_cargo_path = "template/Cargo.toml"
if os.path.exists(template_cargo_path):
with open(template_cargo_path, "r", encoding="utf-8") as f:
content = f.read()

new_content = content.replace('name = "template"', f'name = "{project_name}"')

if content != new_content:
with open(template_cargo_path, "w", encoding="utf-8") as f:
f.write(new_content)
print(f"✅ Updated {template_cargo_path}")
else:
print(f"ℹ️ No changes needed in {template_cargo_path}")
else:
# If the directory was already renamed in a previous run, we might want to check the new name
# but for a simple bootstrap script, assuming standard state is fine.
print(f"⚠️ Warning: {template_cargo_path} not found (Did you already run this script?)")

# 5. Rename template directory
if os.path.exists("template"):
os.rename("template", project_name)
print(f"✅ Renamed directory 'template' to '{project_name}'")
else:
if os.path.exists(project_name):
print(f"ℹ️ Directory '{project_name}' already exists.")
else:
print("⚠️ Warning: Directory 'template' not found.")

print("\n🎉 Bootstrap complete!")
print(f"You can now delete this script: rm {os.path.basename(__file__)}")

if __name__ == "__main__":
main()
133 changes: 0 additions & 133 deletions rename-project.ps1

This file was deleted.

Loading