# Publishing to crates.io
## Prerequisites
1. **Create a crates.io account:**
- Visit https://crates.io/users/register
- Verify your email address
- Log in to get your API token
2. **Get your API token:**
- Log in to https://crates.io
- Go to Account Settings: https://crates.io/me
- Click "New Token" under "API Access"
- Copy the token (you'll only see it once!)
## Publishing the Crate
### Step 1: Test the build locally
```bash
# Check the package
cargo check
# Build the package
cargo build
# Run tests (if any)
cargo test
```
### Step 2: Configure cargo with your API token
```bash
# Set your API token (one-time setup)
cargo login <your_api_token>
# This saves the token to ~/.cargo/credentials.toml
```
Or manually create/edit `~/.cargo/credentials.toml`:
```toml
[registry]
token = "your_api_token_here"
```
### Step 3: Publish to crates.io
```bash
# Make sure you're in the crate directory
cd /Users/ritvikkapila/Documents/workspace/playground/neosigma-rs
# Publish to crates.io
cargo publish
```
### Step 4: Verify
- Check https://crates.io/crates/neosigma
- Your package should be live!
## Important Notes
### Account Setup
- **One token per account**: Unlike PyPI, you use one API token for crates.io
- **Token is reusable**: Once you set it with `cargo login`, you don't need to enter it again
- **Token can be regenerated**: If you lose it, you can create a new one in account settings
### Version Updates
When you want to update:
1. Update `version` in `Cargo.toml`
2. Run `cargo publish` again
3. Version numbers must be higher than the previous version (semantic versioning)
### Package Name Rules
- Package names are **permanently** tied to your account once published
- You can transfer ownership but not rename packages
- Names are case-insensitive: `neosigma`, `NeoSigma`, and `NEOSIGMA` are the same
### Metadata Requirements
Before publishing, ensure:
- ✅ `Cargo.toml` has all required fields (name, version, license, etc.)
- ✅ `README.md` exists (crates.io requires it)
- ✅ `LICENSE` file exists if license is specified
- ✅ Code compiles successfully (`cargo check` passes)
## Troubleshooting
### Error: "the remote server returned an error (status: 400)"
- Check that all required fields in `Cargo.toml` are filled
- Ensure `README.md` exists
- Verify license is properly specified
### Error: "this crate name is already taken"
- Package name is already reserved
- You'll need to choose a different name or contact the owner
### Error: "authentication failed"
- Verify your API token is correct
- Re-run `cargo login` with a fresh token
- Check that your email is verified on crates.io
## Security
- **Never commit your API token** to version control
- The token is saved in `~/.cargo/credentials.toml` (local file, not in repo)
- You can revoke and regenerate tokens from account settings