I built a tool that requires configuration by means of a config.yaml. I'd like to provide a basic version of that file along with the installation. Is it possible to have customizable task carried out (such as creating a directory under /etc/mytool/ and creating a file herein) when running cargo install --path .?
Build Scripts are your friend.
The Rust file designated by the build command (relative to the package root) will be compiled and invoked before anything else is compiled in the package, allowing your Rust code to depend on the built or generated artifacts. By default Cargo looks up for "build.rs" file in a package root (even if you do not specify a value for build).
Use build = "custom_build_name.rs" to specify a custom build name, e.g. add in Cargo.toml:
[package]
# ...
build = "custom_build_name.rs"
Related
I recently started to work on a Go project.
When I use gopls with Coc, all external imports are not recognized such as "github.com/prometheus/client_golang/prometheus". It complains it could not find this module from neither $GOROOT and $GOPATH.
This project is managed by bazel, and all depedencies are listed in WORKSPACE file. Do I have any way to install all packages based on WORKSPACE file or I have to go install all packages one by one? If the latter, I would imagine keep package version synced is challenaging.
To install all dependencies listed in the WORKSPACE file in a Bazel-managed Go project, you can use the bazel run command and the go_repository rule in the WORKSPACE file.
For example, if you have the following go_repository rule in your WORKSPACE file:
go_repository(
name = "com_github_prometheus_client_golang",
importpath = "github.com/prometheus/client_golang",
version = "0.10.0",
)
You can run the following command to install the dependencies:
bazel run //:gazelle
This will run the gazelle target, which updates the dependencies in the WORKSPACE file and generates the required BUILD files for each package in your project.
Once the dependencies are installed, they should be recognized by gopls in your editor.
I want to be able to step though my C++ code for a Node.js addon that I am making. I understand that CMake.js has the --debug option, but there is no documentation about it.
I am using the node-addon-api module, in CLion.
After months of blind debugging though the use of Errors to print variables, I have finally figured out how to attach the CLion debugger to a Node.js addon.
Create a new CMake Application configuration.
Fill in these fields:
Target: Your project
Executable: The Node binary (On Unix do which node or where.exe node on Windows)
Program arguments: Path to your JS file
Working directory: The directory where the JS file is located
Before launch: Build
Start this configuration in debug mode.
I recently stumbled on the same problem and had success creating a custom toolchain in CLion 2020.3 with CMake.js on a Linux system.
Reproducible steps:
Install cmake-js via npm install -g cmake-js. Make sure to install the package globally, so that your toolchain becomes available across multiple projects.
Create a npm project, e.g mkdir my-project && cd my-project && npm init.
Run npm install bindings && npm install node-addon-api (For the C++ wrapper).
Create a CMakeLists.txt in the root directory and paste this. Make sure to replace file(GLOB SOURCE_FILES hello.cpp) with your addon-specific cpp and header files.
Open my-project in CLion.
Go to Settings / Preferences | Build, Execution, Deployment | Custom Build Targets and click + to add a new target.
Go to Build | Tool Settings | Program and set it to the cmake-js binary that you downloaded in the npm directory where you keep your global packages.
Set the arguments to compile -D and set the working directory to the root directory of my-project.
Go to Clean | Tool Settings | Program and set it to the directory where you keep your cmake-js binary. Set the arguments to clean and set the working directory to your project's root directory.
Add a new Run Configuration and specify the Toolchain you just created in the Target field. Point the Executable to your node executable and add the .js file where you import your native addons to. Set the working directory to the current directory as well. Now, you can build the target, and also debug the N-API layer of your native code, too!
I'm trying to build a Rust project (xray). When running cargo run I get the following error message
error: manifest path D:\xray\building\xray\Cargo.toml is a virtual
manifest, but this command requires running against an actual package
in this workspace
What exactly does this mean and how can it be solved? I'm using Cargo version 0.25.0 and Rust version 1.24.1.
Your Cargo.toml is a virtual manifest.
In workspace manifests, if the package table is present, the workspace root crate will be treated as a normal package, as well as a workspace. If the package table is not present in a workspace manifest, it is called a virtual manifest.
When working with virtual manifests, package-related cargo commands, like cargo build, won't be available anymore. But, most of such commands support the --all option, will execute the command for all the non-virtual manifest in the workspace.
cargo run does not work, because cargo doesn't know what to run. There are two options:
--manifest-path <PATH>: Path to Cargo.toml of the crate you want to run.
-p, --package <SPEC>: Package you want to run.
In your case it's probably cargo run --package xray_cli
the manifest has both package and workspace sections can't works. please check the Cargo.toml and remove package from it.
Virtual Manifest is new concepts, please reading docs to familiar it. Hope it values for you.
I need to use rapidjson as a third party library to replace libjson. I'm trying to figure out how to build it so I can use it's build files in my project (dependency list).
I downloaded rapidjson from github, and I'm trying to get a buildable project. I'm looking at the instructions at rapidjson website, and it's showing that I need to do the following, below (Installation).
We don't use git, so what would I need to do instead of the git submodule update --init step?
Why would I need a build dir in the include/rapidjson directory with nothing in it?
When I cd to build and type cmake, it seems to be missing parameters. What is the full cmake command? Thanks!
Installation
RapidJSON is a header-only C++ library. Just copy the include/rapidjson folder to system or project's include path.
RapidJSON uses following software as its dependencies:
•CMake as a general build tool
•(optional)Doxygen to build documentation
•(optional)googletest for unit and performance testing
To generate user documentation and run tests please proceed with the steps below:
1.Execute git submodule update --init to get the files of thirdparty submodules (google test).
2.Create directory called build in rapidjson source directory.
3.Change to build directory and run cmake .. command to configure your build. Windows users can do the same with cmake-gui application.
4.On Windows, build the solution found in the build directory. On Linux, run make from the build directory.
On successfull build you will find compiled test and example binaries in bin directory. The generated documentation will be available in doc/html directory of the build tree. To run tests after finished build please run make test or ctest from your build tree. You can get detailed output using ctest -V command.
It is possible to install library system-wide by running make install command from the build tree with administrative privileges. This will install all files according to system preferences. Once RapidJSON is installed, it is possible to use it from other CMake projects by adding find_package(RapidJSON) line to your CMakeLists.txt.
It is header-only library. So if you just want to integrate it into your project, just copy the /include folder to your project, and it should works.
All other instructions are for building unit tests, performance tests and documentation.
I need to build an executable to test the environment and generate configuration for the following steps of building process. How can I tell Cabal to build such an executable during the configuration stage and not to install it as a part of the distribution?
Modern cabal now has a setup-depends field that lets you specify custom dependencies to your setup script (see: http://cabal.readthedocs.io/en/latest/developing-packages.html?highlight=setup-depends#custom-setup-scripts)
As such, your setup script can now use whatever libraries you want to import.