Problems when using Sublime Text 3 to build rust file


#1
{
"cmd":["rustc","$file","-o","$file_path/$file_base_name"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.rust",

"variants": [
    {
        "name": "Run",
        "cmd": ["./$file_base_name"]
    }
]
}

This is my sublime.build file for Rust. Why the error following appeared?

[Errno 2] No such file or directory: './hello_world'
[cmd: ['./hello_world']]
[dir: /Users/R/Desktop]
[path: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin]
[Finished]

#2

Can’t say I know anything about how this works, but it looks like you are outputting the executable to one directory ("$file_path/$file_base_name") and tries to run it somewhere else ("./$file_base_name").


#3

I use this build file, it is the Cargo.sublime-build from https://github.com/jhasse/sublime-rust/blob/master/Cargo.sublime-build, but changed to use the project directory as the working directory.

Note that this is using cargo instead of rustc.

{
    "cmd": ["cargo", "build"],
    "file_regex": "^(.*?):([0-9]+):([0-9]+):\\s[0-9]+:[0-9]+\\s(.*)$",
    "syntax": "Packages/Makefile/Make.build-language",
    "selector": "source.rust",

    "working_dir": "$folder",

    "variants": [
        {
            "cmd": ["cargo", "run"],
            "name": "Run"
        },
        {
            "cmd": ["cargo", "test"],
            "name": "Test"
        }
    ]
}

I think the reason that yours do not work is that you are changing the cmd from “rustc …” to “./hello_world”. I think the variant does not add to the commands runned. However I am no expert in the sublime build files.