Skip to content

New Cargo build system. #165

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

Merged
merged 32 commits into from
Jul 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e3e1e4b
New Cargo build system.
ehuss Mar 12, 2017
621dbe7
Fix wrapping of commands in GitHub flavored markdown.
ehuss Mar 13, 2017
d2e13ee
Minor fixes to unittests for Rust 1.16.
ehuss Mar 16, 2017
81aadd9
Add support for "cargo check".
ehuss Mar 17, 2017
c2704f8
Support clippy for on-save checking.
ehuss Mar 17, 2017
b64b5a5
Fix on-save syntax check running clippy multiple times.
ehuss Mar 18, 2017
4b0ee0f
Add ability to configure cargo build features.
ehuss Mar 18, 2017
4b39081
Support setting environment variables.
ehuss Mar 19, 2017
caa482f
Normalize paths when dealing with settings.
ehuss Mar 19, 2017
5f53d83
Disable on-load message display for tests.
ehuss Mar 19, 2017
160a7f2
Fix race condition in tests manifested on linux.
ehuss Mar 19, 2017
b2bc6ed
Add support for custom build variants.
ehuss Mar 21, 2017
35f30e7
Add support for a default path/package.
ehuss Mar 21, 2017
44c99db
Add "Automatic" build variant.
ehuss Mar 21, 2017
e01b25e
Stop looking for JSON output during Cargo build once compile is finis…
ehuss Mar 29, 2017
cf81124
Better fix for checking when we should stop looking for JSON output.
ehuss Mar 29, 2017
a60e264
Remove debug print left behind.
ehuss Mar 31, 2017
41b23d7
Minor updates for rust 1.17.
ehuss Apr 28, 2017
d506158
Change message tests to check the region of the message.
ehuss May 6, 2017
7360da4
Fix error highlighting for nested macros.
ehuss May 6, 2017
5062a4f
Fix clearing of error regions.
ehuss May 6, 2017
f288027
Add rust_phantom_style and rust_region_style config settings.
ehuss May 6, 2017
25111f1
Honor show_errors_inline config setting for Cargo build.
ehuss May 6, 2017
adb33f2
Fix links in messages that are surrounded by angled brackets.
ehuss May 11, 2017
b81d0e1
Consolidate all Cargo config commands into a single command.
ehuss May 14, 2017
83a3416
Document the new build configure command.
ehuss May 14, 2017
62af8f1
On-save syntax checking now uses configuration settings from the build
ehuss May 15, 2017
d9d40ea
Finish documenting all settings, and include link to new build docs.
ehuss May 15, 2017
a2f869d
Fix Cargo environment variable config command when selecting "all build
ehuss May 30, 2017
6eebab6
Only print warning about sublime-project when saving setings.
ehuss May 31, 2017
94e3606
Fix target detection for cdylib.
ehuss May 31, 2017
ae61e33
Update tests for new messages in rust 1.18.
ehuss Jun 8, 2017
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
8 changes: 7 additions & 1 deletion Cargo.build-language
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<key>name</key>
<string>variable.parameter</string>
</dict>
<dict>
<key>match</key>
<string>^warning:</string>
<key>name</key>
<string>variable.parameter</string>
</dict>
<dict>
<key>match</key>
<string>^test result:</string>
Expand Down Expand Up @@ -108,4 +114,4 @@
<key>scopeName</key>
<string>source.build_results</string>
</dict>
</plist>
</plist>
53 changes: 0 additions & 53 deletions Cargo.sublime-build

This file was deleted.

17 changes: 17 additions & 0 deletions Default (Linux).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{"keys": ["f4"], "command": "rust_next_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["ctrl+break"], "command": "rust_cancel", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
]
17 changes: 17 additions & 0 deletions Default (OSX).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{"keys": ["f4"], "command": "rust_next_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["ctrl+c"], "command": "rust_cancel", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
]
17 changes: 17 additions & 0 deletions Default (Windows).sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{"keys": ["f4"], "command": "rust_next_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["shift+f4"], "command": "rust_prev_message", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
{"keys": ["ctrl+break"], "command": "rust_cancel", "context":
[
{"key": "selector", "operator":"equal", "operand": "source.rust"}
]
},
]
45 changes: 23 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ If you can't see `Rust Enhanced` its most likely because you're using Sublime Te

## Features
### Go To Definition
### Build functionality
Rust Enhanced has the following build functions:
- Cargo Check
- Cargo Run
- Cargo Script [Cargo Script is needed](https://github.com/DanielKeep/cargo-script)
- Cargo Test
- Cargo Bench
- Cargo Clean
- Cargo Release
- Cargo Document
- Cargo Clippy
- Rust
- Rust Run
### Cargo Build
Rust Enhanced has a custom build system tailored for running Cargo. It will display errors and warnings in line using Sublime's phantoms. It also supports a variety of configuration options to control how Cargo is run.

![testingrust](https://cloud.githubusercontent.com/assets/43198/22944409/7780ab9a-f2a5-11e6-87ea-0e253d6c40f6.png)

See [the build docs](docs/build.md) for more information.

### Cargo tests with highlighting
Thanks to [urschrei](https://github.com/urschrei/) we have Highlighting for:
Expand All @@ -53,24 +45,31 @@ Thanks to [urschrei](https://github.com/urschrei/) we have Highlighting for:
- total number of measured tests > 0

Example:

![highlight_rust_test](https://cloud.githubusercontent.com/assets/936006/19247437/3cf6e056-8f23-11e6-9bbe-d8c542287db6.png)

### Syntax Checking
Rust Enhanced will automatically perform syntax checking each time you save a file.
Errors and warnings are displayed in line the same way as the [build system](docs/build.md).
This relies on Cargo and Rust (>= 1.8.0) being installed and on your system path. Plus Sublime Text >= 3118.

There are a variety of settings (see [Settings](#settings)) for controlling the syntax highlighting:
[Settings](#settings) for controlling the on-save syntax checking:

| Setting | Default | Description |
| :------ | :------ | :---------- |
| `rust_syntax_checking` | `true` | Enable the on-save syntax checking. |
| `rust_syntax_checking_include_tests` | `true` | Enable checking of test code within `#[cfg(test)]` sections. |
| `rust_syntax_hide_warnings` | `false` | If true, will not display warning messages. |
| `rust_syntax_error_color` | `"#F00"` | Color of error messages. |
| `rust_syntax_warning_color` | `"#FF0"` | Color of warning messages. |
| `rust_syntax_checking_include_tests` | `true` | Enable checking of test code within `#[cfg(test)]` sections (only for `no-trans` method). |
| `rust_syntax_checking_method` | `"no-trans"` | The method used for checking your code (see below). |

Here is an example:
![testingrust](https://cloud.githubusercontent.com/assets/43198/22944409/7780ab9a-f2a5-11e6-87ea-0e253d6c40f6.png)
The available checking methods are:

| Method | Description |
| :----- | :---------- |
| `no-trans` | Runs the rustc compiler with the `-Zno-trans` option. This will be deprecated soon, however it has the benefit of supporting `#[test]` sections. |
| `check` | Uses `cargo check` (requires at least Rust 1.16). |
| `clippy` | Uses `cargo clippy`. This requires [Clippy](https://github.com/Manishearth/rust-clippy) to be installed. This also may be a little slower since it must check every target in your package. |

This will use the same configuration options as the "Check" and "Clippy" build variants (for example, extra environment variables, or checking with different features). See [the build docs](docs/build.md) for more information.

Projects with multiple build targets are supported too (--lib, --bin, --example, etc.). If a cargo project has several build targets, it will attempt to automatically detect the correct target. In some rare cases, you may need to manually specify which target a file belongs to. This can be done by adding a "projects" setting in `Rust.sublime-settings` with the following format:

Expand All @@ -93,9 +92,11 @@ Projects with multiple build targets are supported too (--lib, --bin, --example,
```

## Settings
You can customize the behaviour of sublime-rust by creating a settings file in your User package. This can be accessed from within SublimeText by going to the menu Preferences > Browse Packages.... Create a file named Rust.sublime-settings or alternatively copy the default settings file Packages/sublime-rust/Rust.sublime-settings to your User package and edit it to your liking.
To customize the settings, use the command from the Sublime menu:

Preferences > Package Settings > Rust Enhanced > Settings - User

Note: File names are case-sensitive on some platforms (e.g. Linux) so the file name should be exactly Rust.sublime-settings with capitalization preserved.
Additionally, you can customize settings per-project by adding settings to your `.sublime-project` file under the `"settings"` key.

## Development

Expand Down
61 changes: 49 additions & 12 deletions RustEnhanced.sublime-build
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
{
"shell_cmd": "rustc \"$file\"",
"target": "cargo_exec",
"selector": "source.rust",
"file_regex": "[ \\t]*-->[ \\t]*(.*?):([0-9]+):([0-9]+)$",
"osx":
{
"path": "~/.cargo/bin:$path",
},
"command": "build",

"variants": [
{
"selector": "source.rust",
"shell_cmd": "./$file_base_name",
"name": "Automatic",
"command": "auto",
},
{
"name": "Run",
"windows":
{
"shell_cmd": "\"$file_base_name.exe\""
"command": "run",
},
{
"name": "Run (with args)...",
"command": "run",
"command_info": {
"wants_run_args": true
}
},
{
"name": "Check",
"command": "check",
},
{
"name": "Test",
"command": "test",
},
{
"name": "Test (with args)...",
"command": "test",
"command_info": {
"wants_run_args": true
}
}
},
{
"name": "Bench",
"command": "bench",
},
{
"name": "Clean",
"command": "clean",
},
{
"name": "Document",
"command": "doc",
},
{
"name": "Clippy",
"command": "clippy",
},
{
"name": "Script",
"command": "script",
},
]
}
26 changes: 23 additions & 3 deletions RustEnhanced.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
[
{
"caption": "Rust: Toggle Syntax Checking",
{
"caption": "Rust: Toggle Syntax Checking",
"command": "toggle_rust_syntax_setting"
}
},
{
"caption": "Rust: Next Message",
"command": "rust_next_message"
},
{
"caption": "Rust: Prev Message",
"command": "rust_prev_message"
},
{
"caption": "Rust: Cancel Build",
"command": "rust_cancel"
},
{
"caption": "Rust: Create New Cargo Build Variant",
"command": "cargo_create_new_build"
},
{
"caption": "Rust: Configure Cargo Build",
"command": "cargo_configure"
},
]
19 changes: 18 additions & 1 deletion RustEnhanced.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,24 @@
"rust_syntax_error_color": "#F00",

// Color of warning messages.
"rust_syntax_warning_color":"#FF0"
"rust_syntax_warning_color":"#FF0",

// Specify environment variables to add when running Cargo.
// "rust_env": {"PATH": "$PATH:$HOME/.cargo/bin"}

// If true, will use the environment from the user's login shell when
// running Cargo.
"rust_include_shell_env": true,

// For errors/warnings, how to show the inline message.
// "normal" - Shows the message inline.
// "none" - Do not show the message inline.
"rust_phantom_style": "normal",

// For errors/warnings, how to highlight the region of the error.
// "outline" - Outlines the region.
// "none" - No outlining.
"rust_region_style": "outline",

// If your cargo project has several build targets, it's possible to specify mapping of
// source code filenames to the target names to enable syntax checking.
Expand Down
Loading