Setuptools for Rust application

Hi,

I am new to rust. Started playing with rust from the beginning of the year. Looking for if there is a tool
that can compile my application and push it to Linux executable like using the setuptools in Python.
https://github.com/pypa/setuptools

Or is there any other way that I can do it without using this setuptools to make an executable for
my application in Linux/Fedora and run it in the terminal.

Thanks a lot,
Leo

I'm sorry, I don't completly understand what it is you are trying to achieve and I'm not familiar with setuptools, are you trying to compile code? Like cargo build? Or are you trying to push it onto crates.io? Like cargo push? Or are you trying to push it onto a package manager for your flavour of Linux? Eg Ubuntu?

I'm not familiar with setuptools, but I'm guessing you want to produce a runnable executable? Rust actually does this for you every time you run or build the code, as it is a compiled language contrary to python.

After running cargo build --release you will find a runnable executable located at target/release/[name-of-program].

Note that this also happens with cargo build, but with --release your application will be compiled with more optimizations. (without --release the executable is found in target/debug instead)

1 Like

General Reply:

Thank you so much for your reply. Highly appreciate all the comments or suggestions. You reply helps a lot to me, to be honest.

Sorry for being confused in my question. Let me explained setuptools, based on my understanding, a little bit. Python setuptools you to manage your python packages easily with one line in the terminal.

python setup.py install

This is able to install your python package to the system and create executable for your python program. Inside the setup.py is a very straightforward function that do all the dirty work for you.

# setup.py example

import os
from setuptools import setup

# Utility function to read the README file.
# Used for the long_description.  It's nice, because now 1) we have a top level
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

setup(
    name = "an_example_pypi_project",
    version = "0.0.4",
    author = "Andrew Carter",
    author_email = "andrewjcarter@gmail.com",
    description = ("An demonstration of how to create, document, and publish "
                                   "to the cheese shop a5 pypi.org."),
    license = "BSD",
    keywords = "example documentation tutorial",
    url = "http://packages.python.org/an_example_pypi_project",
    packages=['an_example_pypi_project', 'tests'],
    long_description=read('README'),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Topic :: Utilities",
        "License :: OSI Approved :: BSD License",
    ],
)

Here are the link for the repo and document.

By comparing this with Rust, I think Cargo is the think in Rust, which is managing the crate for Rust.

============================================================
For what I am looking for is just a tool that can compile my crate and make an executable binary that can run in my Linux/Fedora system by just typing myApp --arg in the terminal.

I think @alice gave me a good idea that I can just place my executable under the /usr/local/bin which allows the PATH to look for it and run.

Once again, thanks for your answers. Please forgive if what I said doesn't make sense, since I am still a Rookie.

Take a look at this then:
https://github.com/rust-lang/cargo/issues/6100
To automatically copy the artifact to /usr/local/bin on compile. Note that you can also pass arguments to the compiled program like so when just using cargo:

cargo run -- --your --own --arguments = "everything after the --"

If you're looking for a way to automatically install your package, it's also possible with cargo. You can upload your crate to crates.io using cargo publish and then you can install it using cargo install package_name. The binary will be installed into ~/.cargo/bin.

1 Like

Thanks for sharing. This is looks like a good to way to copy the executable.

This looks like a good way to meet my need. Thanks for sharing.