An example project showing usage of CMake with Rust

Overview

An example of using CMake with Rust.

Build Status

Try it!

mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/tmp
make -j
make test -j
make doc -j
make install

cd examples
./example1
./example2

License:

The example files are released into the public domain, and the CMake modules are licensed under the zlib license (see file contents).

You might also like...
Demo app duplicated in 5 languages (Go/JavaScript/Python/Ruby/Rust) showing how to go from source code to container image using melange+apko

hello-melange-apko 💫 This repo contains an example app duplicated across 5 languages showing how to: Package source code into APKs using melange Buil

An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.
An inquiry into nondogmatic software development. An experiment showing double performance of the code running on JVM comparing to equivalent native C code.

java-2-times-faster-than-c An experiment showing double performance of the code running on JVM comparing to equivalent native C code ⚠️ The title of t

Showing how to deploy a Terra smart contract using Chainlink Data Feeds

Chainlink Terra Developing Requirements This demo requires the following components: Rust: rustup with cargo 1.44.1+. rustc and cargo 1.44.1+. Install

A few demos showing how to estimate projects using Monte Carlo simulations.

Agile Monte Carlo Simulations Demos This is the repository which accompanies the blog post "How to replace estimations and guesses with a Monte Carlo

A cargo plugin for showing a tree-like overview of a crate's modules.

cargo-modules Synopsis A cargo plugin for showing an overview of a crate's modules. Motivation With time, as your Rust projects grow bigger and bigger

Update Twitter profile with a meter showing how close you are to code burnout.

WakaTime Code Burnout Meter in Twitter Profile Inspired by trash's Twitter profile, this repo adds a burnout meter to your Twitter profile. It uses Wa

Custom module for showing the weather in Waybar, using the great wttr.io
Custom module for showing the weather in Waybar, using the great wttr.io

wttrbar a simple but detailed weather indicator for Waybar using wttr.in. Installation Compile yourself using cargo build --release, or download the p

This project is based on code from freertos.rs and some additions to simplify the usage of FreeRTOS in embedded applications written in Rust

FreeRTOS-rust This project is based on code from freertos.rs and some additions to simplify the usage of FreeRTOS in embedded applications written in

An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

Rust ESP32 Example An example project demonstrating integration with Rust for the ESP32-S2 and ESP32-C3 microcontrollers.

This is an example Nostr rust project to enable '402 Payment Required' responses for requests to paid content.

Nostr Paywall Example This is an example Nostr rust project to enable 402 Payment Required responses for requests to paid content. To prove payment, a

A basic rp2040-hal project with blinky and rtt logging example code.

A basic rp2040-hal project with blinky and rtt logging example code. With this you can quickly get started on a new rp2040 project

The point of this anchor project is to serve as a starter kit or example to compose with mango-v3 using anchor.

The point of this anchor project is to serve as a starter kit or example to compose with mango-v3 using anchor. It currently provides 2 examples and various inline todos on how to extend this.

Example NFT marketplace project using ink! smart contract.

NFT Marketplace project This contract is an example for the NFT marketplace implementation. License Apache 2.0 🏗️ How to use - Contracts 💫 Build Use

Example app & project structure for Golem Cloud

Synopsis This project serves as an example/template for building an application using WebAssembly Component Model (and in this case, an app for Ziverg

A collection of example project using Njord.
A collection of example project using Njord.

Example Projects A collection of example project using Njord. Contributors The following contributors have either helped to start this project, have c

Detects usage of unsafe Rust in a Rust crate and its dependencies.
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ A program that lists statistics related to the usage of unsafe Rust code in a Rust crate and all its dependencies. This cargo plugin w

Detects usage of unsafe Rust in a Rust crate and its dependencies.
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ A program that lists statistics related to the usage of unsafe Rust code in a Rust crate and all its dependencies. This cargo plugin w

Detects usage of unsafe Rust in a Rust crate and its dependencies.
Detects usage of unsafe Rust in a Rust crate and its dependencies.

cargo-geiger ☢️ Looking for maintainer: https://github.com/rust-secure-code/cargo-geiger/issues/210 A program that lists statistics related to the usa

This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust to play back video files.

FFmpeg Rust Video Player This is a lightweight audio-video player built in Rust using FFmpeg libraries. It demonstrates the usage of FFmpeg with Rust

Comments
  • Makefile build on OSX doesn't seem to work~

    Makefile build on OSX doesn't seem to work~

    Results in:

    make[2]: *** No rule to make target `CMakeFiles/TEST.dir/depend'.  Stop.  
    make[1]: *** [CMakeFiles/TEST.dir/all] Error 2 
    make: *** [all] Error 2    
    

    That said, using ninja seems to work just fine, if you invoke cmake using:

    $ cmake .. -G "Ninja"
    $ ninja
    [3/3] Building examples/example2
    $ ./examples/example1
    Hello
    

    Not particularly fussed; I use ninja for everything anyway, but I thought I'd drop this in as a heads up.

    opened by shadowmint 5
  • What is the status of this project now that Cargo is catching wind?

    What is the status of this project now that Cargo is catching wind?

    I ask because I'd like to use this, particularly because I'm not happy about the support of externals in cargo (build.rs "scripts" etc seem more complicated than the cmake analogue). To me it seems like a less complicated situation to have a project built using cmake that can build it's cargo dependencies using cmakes ExternalProject support instead.

    But I don't want to do that if this is going to be adandoned. :/ Perhaps I need to just drink the punch.

    opened by photex 2
  • Project using getopts does not compile

    Project using getopts does not compile

    Hi!

    There is a multilanguage project that cries out for CMake, and Rust is one of them, but I would save ourselves from using muliple flavors of make. (Note that I am not the author of the Rust sources, I am just responsible for holding the project together. There are several developers, each responsible for one language.)

    There is a manybody-rust-common.rs crate that holds common functionality for all executables, one being parsing arguements using getopts. Then there are multiple executables manybody-rust-v0, v1, v2, etc. that use this common crate.

    What is the best way to compile this? In a C/C++ world I would compile manybody-rust-common to a dynamic or static library and link to it. The author of the Rust sources is a Rust newbie and has a hard time answering what Cargo and rustc under the hood are doing (which I do not blame him for, as Rust on Windows is not trivial). He came up with the following Cargo script:

    [package]
    
    name = "manybody"
    version = "0.0.1"
    authors = ["Email here"]
    
    [[bin]]
    name = "manybody0"
    path = "src/manybody0.rs"
    
    [[bin]]
    name = "manybody1"
    path = "src/manybody1.rs"
    
    ...
    
    [dependencies]
    getopts = "*"
    

    This compiles just fine. Trying to build this with CMake, I came up with the following script using the RustCMake module for the common part:

    project (manybody-rust-common)
    
    set (Project_Base_Dir ../../manybody/)
    
    set (CMAKE_USE_RELATIVE_PATH "true")
    
    set (Files_SRCS)
    set (Files_SRCS ${Project_Base_Dir}/src/comp_phys_common.rs)
    
    set (Files_BUILD ${Files_SRCS})
    
    # Create filters for IDEs
    source_group ("Sources" FILES ${Files_SRCS})
    
    # Get the dependencies of all the crates
    get_rust_deps(${Files_SRCS} manybody-rust-common_DEPS COMPILE)
    
    # Build the library
    rust_crate(${Files_SRCS}
           ALL
           TARGET_NAME ${PROJECT_NAME}
           DESTINATION lib/${CONFIGURATION_NAME})
           DEPENDS "${manybody-rust-common_DEPS}")
    

    And this is the script for the v0 executable:

    project (manybody-rust-v0)
    
    set (Project_Base_Dir ../../manybody/)
    
    set (CMAKE_USE_RELATIVE_PATH "true")
    
    set (Files_SRCS)
    set (Files_SRCS ${Project_Base_Dir}/src/manybody0.rs)
    
    set (Files_BUILD ${Files_SRCS})
    
    # Create filters for IDEs
    source_group ("Sources" FILES ${Files_SRCS})
    
    # Get the dependencies of all the crates
    get_rust_deps(${Files_SRCS} manybody-rust-v0_DEPS)
    
    # Build examples
    rust_crate(${Files_SRCS}
           ALL
           TARGET_NAME ${PROJECT_NAME}
           DESTINATION bin/${CONFIGURATION_NAME}
           DEPENDS "${manybody-rust-common_FULL_TARGET};${manybody-rust-v0_DEPS}")
    

    However when I try to build my project, this is what I get:

    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:32:37: 32:53 error: use of undeclared type name `getopts::Options`
    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:32 fn print_usage(program: &str, opts: getopts::Options) {
                                                                                                                                   ^~~~~~~~~~~~~~~~
    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:42:20: 42:41 error: failed to resolve. Could not find `Options` in `getopts`
    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:42     let mut opts = getopts::Options::new();
                                                                                                                              ^~~~~~~~~~~~~~~~~~~~~
    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:42:20: 42:41 error: unresolved name `getopts::Options::new`
    C:/Users/nagy-_000/Git/comp-phys/manybody/rust/cmake/common/../../manybody//src/comp_phys_common.rs:42     let mut opts = getopts::Options::new();
                                                                                                                              ^~~~~~~~~~~~~~~~~~~~~
    error: aborting due to 3 previous errors
    NMAKE : fatal error U1077: 'C:\Kellekek\Open-Source\Rust\1.0.0-beta\bin\rustc.exe' : return code '0x65'
    Stop.
    NMAKE : fatal error U1077: '"C:\Kellekek\Microsoft\Visual Studio\14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
    Stop.
    NMAKE : fatal error U1077: '"C:\Kellekek\Microsoft\Visual Studio\14.0\VC\BIN\amd64\nmake.exe"' : return code '0x2'
    Stop.
    
    • How can I alter my CMake scripts so that it correctly picks up getopts and common?
    • The RustCMake example script shows how to add unit test, but that does not integrate with the native unit test mechanism, which we do employ for all the other languages. Can the Rust executables integrate to the other tests? (in the native test target?)

    Rust is a hell of a language with enormous potential, but I detest how strongly the means of compiling and distributing Rust interacts with the language itself. #pragma lib() is the evil counterpart to this in C++. Source code should have nothing to do with how I want to compile an application. Source code should not contain filenames, neither should a build system depend on directory structure or file naming conventions. It seems Rust has taken a direction where it is getting harder and harder to compile Rust without Cargo. Why should I, a package maintainer (so to say) have to learn a whole new make language just because it goes hand-in-hand with a language? Rust is not born into vacuum, and I think the community should focus more on Rust integrating with other tools, such as the VS Add-In, and RustCMake. If not promote, at least mention them on rust-lang.org.

    opened by MathiasMagnus 3
Owner
null
GitHub Actions for mdBook (rust-lang/mdBook) ⚡️ Setup mdBook quickly and build your site fast. Linux (Ubuntu), macOS, and Windows are supported.

GitHub Actions for mdBook rust-lang/mdBook Setup Action. We can run mdBook on a virtual machine of GitHub Actions by this mdBook action. Linux, macOS,

Shohei Ueda 231 Jan 2, 2023
Webpack loader for Rust files. DEPRECATED, use WasmPack instead

The project is in low maintance now Use WasmPack instead Webpack Rust loader Webpack loader for Rust Example add.rs #[no_mangle] pub fn add(a: i32, b:

Max Eliseev 36 Jan 12, 2022
Generate a Python module from a single Rust file.

cargo-single-pyo3 Utility to build Python modules from a single Rust files via pyo3. Inspired by cargo-single. Installation cargo install cargo-single

Will Crichton 6 Dec 30, 2022
A simple library for use one Rust code in multi platforms such as WebAssembly, Android and iOS

chameleon chameleon is a simple library for use one Rust code in multi platforms such as WebAssembly, Android and iOS. Key Features TBA Quick Start TB

Chris Ohk 3 Oct 18, 2021
ttvm is a runtime and compiler infrastructure written in Rust.

ttvm - Runtime and compiler infrastructure ttvm is a runtime and compiler infrastructure written in Rust. Usage Add the following to your Cargo.toml:

maDeveloper 1 Apr 19, 2022
🦎 Prototypes on polymorphic, metamorphic and poly-metamorphic malwares in Rust 🦎

chameleon-rs Prototypes on polymorphic, metamorphic and poly-metamorphic malwares in Rust. Disclaimer This project is for educational purposes only. I

Quartz Technology 8 Nov 2, 2023
A toy example showing how to run Rust code in Python for speed and progress.

PoC: Integrating Rust in Python A toy example showing how to run Rust code in Python for speed and progress. Requirements Python 3.6+ Rust 1.44+ Cargo

Emil Thorenfeldt 2 Feb 7, 2022
Example showing how to use tokio and egui together.

Example using tokio with egui This example uses reqwest to send an HTTP request to httpbin. The parsed response contains an increment value (as provid

Jay Oster 10 Dec 25, 2022
dua (-> Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory

dua (-> Disk Usage Analyzer) is a tool to conveniently learn about the usage of disk space of a given directory. It's parallel by default and will max

Sebastian Thiel 1.8k Jan 2, 2023
A shared document application akin to Google Docs. Example usage of wasm-peers library.

Live Document Proof of concept application showcasing the usability of wasm-peers crate for easy and costless peer-2-peer WebRTC communication. It's a

null 6 Sep 19, 2022