Rust-analyzer in VSCode to substitute env variables in Cargo path imports - rust

I have a Cargo workspace and want to use a WORKSPACE_HOME environment variable in the import path of local crates.
For instance: in $WORKSPACE_HOME/services/api/Cargo.toml
[dependencies]
...
addrbook = { path = "${WORKSPACE_HOME}/pkg/addrbook" }
...
I tried adding the environment value to VSCode settings.json (under rust-analyzer.cargo.extraEnv) and also tried creating a .cargo/config.toml as described here
[env]
WORKSPACE_HOME = { value = "", relative = true }
Unfortunately, cargo metadata keeps failing saying that it is unable to resolve the path
[ERROR rust_analyzer::lsp_utils] rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /Users/nickdecooman/Documents/Workspace/foobar/Cargo.toml, Some(Version { major: 1, minor: 63, patch: 0 }): Failed to run `"cargo" "metadata" "--format-version" "1" "--manifest-path" "/Users/nickdecooman/Documents/Workspace/foobar/Cargo.toml" "--filter-platform" "x86_64-apple-darwin"`: `cargo metadata` exited with an error: error: failed to load manifest for workspace member `/Users/nickdecooman/Documents/Workspace/foobar/services/api`
Caused by:
failed to load manifest for dependency `addrbook`
Caused by:
failed to read `/Users/nickdecooman/Documents/Workspace/foobar/services/api/${WORKSPACE_HOME}/pkg/addrbook/Cargo.toml`
Caused by:
No such file or directory (os error 2)

Related

Getting "error TS2307: Cannot find module" when deploynig code using ml-gradle

When I trying to deploying the code on ml server(10.0-9.4) ,with below build.gradle file , we are getting the below mentioned error:
In this deployment, I want to avoid the loading of ts(src/test/rule10.test.ts) file , is there any way to do so as it is not required and dependent on other modules.
command used :
./gradlew -b build.gradle loadRules -i -PmlUsername="" -PmlPassword="" -PmlHost="localhost"
build.gradle
plugins {
// node
// id "com.moowork.node" version "1.1.1"
// ML-Gradle will handle the marklogic configuration
id 'com.marklogic.ml-gradle' version '4.1.0'
id "com.github.node-gradle.node" version "3.1.1"
}
// Set up extra properties to configure ml-gradle
ext {
// set up the default IDDN databases
mlAppConfig {
contentDatabaseName = 'data1'
schemasDatabaseName = 'Schemas'
modulesDatabaseName = 'Modules'
triggersDatabaseName = 'Triggers'
}
mlAppDeployer.getCommand('DeployCustomForestsCommand').setCustomForestsPath("forests")
// mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand("DeployRolesCommand"))
// do not let ml-gradle create a default rest server - we will only use the json config files
mlAppDeployer.getCommands().remove(mlAppDeployer.getCommand('DeployRestApiServersCommand'))
}
repositories {
mavenCentral()
// Needed for mlcp dependencies
maven { url 'https://developer.marklogic.com/maven2/' }
}
configurations {
mlcp
}
dependencies {
mlcp 'com.marklogic:mlcp:10.0.9.2'
mlcp files('lib')
}
// Control nodejs and NPM build tasks via gradle
node {
// Version of node to use.
version = '10.14.1'
npmVersion = '6.4.1'
download = true
}
// do not spam NPM error messages, the tools' own messages are fine.
npm_run_clean {
args = ['--loglevel', 'silent']
}
npm_run_build {
args = ['--loglevel', 'silent']
}
npm_run_test {
args = ['--loglevel', 'silent']
}
task loadJSON(type: com.marklogic.gradle.task.MlcpTask, dependsOn: []) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root/a1.json'
document_type = 'json'
output_uri_replace = "^.*root,''"
}
// temp workaround to facilitate ns and collections
task loadJS(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [npm_run_clean, npm_run_build]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
}
task loadRules(type: com.marklogic.gradle.task.MlcpTask, dependsOn: [mlClearModulesDatabase, mlClearSchemasDatabase, mlLoadSchemas, loadJS, loadJSON]) {
classpath = configurations.mlcp
command = 'IMPORT'
database = 'Modules'
input_file_path = './src/main/ml-modules/root'
document_type = 'text'
output_uri_replace = "^.*root,''"
output_uri_suffix = ".sjs"
}
mlLoadSchemas.mustRunAfter(mlClearSchemasDatabase)
npm_run_build{}.mustRunAfter(npm_run_clean)
loadJS.mustRunAfter(npm_run_build)
loadJS.mustRunAfter(mlClearModulesDatabase)
loadJSON.mustRunAfter(loadJS)
loadRules.mustRunAfter(loadJS)
error:
> Task :npm_run_build
Caching disabled for task ':npm_run_build' because:
Build cache is disabled
Task ':npm_run_build' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Starting process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''. Working directory: /var/opt/redaction Command: /var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm run build --loglevel silent
Successfully started process 'command '/var/opt/redaction/.gradle/npm/npm-v6.4.1/bin/npm''
src/test/rule12.test.ts(3,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule11.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule10.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test7.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/test5.ts(3,36): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule3.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule2.test.ts(2,38): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
src/test/rule1.test.ts(3,33): error TS2307: Cannot find module 'marklogic-test-harness'.
> Task :npm_run_build FAILED
:npm_run_build (Thread[Execution worker for ':',5,main]) completed. Took 3.295 secs.
Please any one can help me on this.
You could look to apply properties to only include (or to exclude) certain module filename patterns:
https://github.com/marklogic-community/ml-gradle/wiki/Property-reference#module-and-schema-properties
mlModulesRegex New in 3.3.0 - when running mlLoadModules or mlReloadModules, only load modules with a file path matching the given regex pattern. No default value.
mlResourceFilenamesToExcludeRegex New in 3.0.0 - regex that defines resource filenames to exclude from processing (exclude = ignore). Useful for when you want to exclude a set of resources when deploying to a certain environment. Cannot be set when mlResourceFilenamesToIncludeRegex is also set. No default value.

How to resolve circular dependency in compilation of node modules?

I am using yarn workspaces and have a project (proj1) which uses a library I wrote (proj2), which had been initialised with create-react-library when I started it. My library uses visx in some of the components. Everything was fine until I added the last line in my index.js file, exporting another component that is build with visx:
export { ConfigField } from './ConfigField';
export { ConfigPage } from './ConfigPage';
export { SaveButton } from './SaveButton';
export { PageLoadingIndicator } from './PageLoadingIndicator';
export { UsersPage } from './UsersPage';
export { AnalyticValue } from './AnalyticValue';
export { DonutChart } from './DonutChart';
export { SingleValueDonutChart } from './SingleValueDonutChart';
export { Alert } from './Alert';
export { FormDialog } from './FormDialog';
export { TimeSeriesChart } from './TimeSeriesChart';
Somehow, after the addition of this export, when building proj2 a circular dependency is created. I suspect this is to do with compiling to have CJS imports.
PS C:\usr\git\proj2> yarn
yarn install v1.22.5
warning package.json: No license field
[1/4] Resolving packages...
success Already up-to-date.
$ run-s build
yarn run v1.22.5
warning package.json: No license field
$ microbundle-crl --no-compress --format modern,cjs
Circular dependency: ..\node_modules\#visx\axis\esm\index.js -> ..\node_modules\#visx\axis\esm\axis\Axis.js -> ..\node_modules\#visx\axis\esm\axis\AxisRenderer.js -> ..\node_modules\#visx\axis\esm\index.js
Non-existent export 'TextProps' is imported from ..\node_modules\#visx\text\esm\types.js
Error: 'TextProps' is not exported by ..\node_modules\#visx\text\esm\types.js, imported by ..\node_modules\#visx\text\esm\Text.js
at C:\usr\git\proj1\node_modules\#visx\text\esm\Text.js:8:9
6: import useText from './hooks/useText';
7: import { TextProps } from './types';
8: export { TextProps } from './types';
^
9: var SVG_STYLE = {
10: overflow: 'visible'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "build" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
How can I fix this circular dependency? Is there a plugin I should be using?
Solved. The problem was actually pretty basic. I realised I was importing from #visx/axis without having it explicitly in my package.json. 🤦 After adding explicitly, it works.

"Failed to parse manifest" when compiling rustc using a locally-modified copy of the libc crate

I need to build the rustc compiler using a modified libc crate. I cloned the libc directory and made the changes, now how do I include the modified libc in my build?
This is my Cargo.toml
[patch.crates-io]
# Similar to Cargo above we want the RLS to use a vendored version of `rustfmt`
# that we're shipping as well (to ensure that the rustfmt in RLS and the
# `rustfmt` executable are the same exact version).
rustfmt-nightly = { path = "src/tools/rustfmt" }
# See comments in `src/tools/rustc-workspace-hack/README.md` for what's going on
# here
rustc-workspace-hack = { path = 'src/tools/rustc-workspace-hack' }
# See comments in `tools/rustc-std-workspace-core/README.md` for what's going on
# here
rustc-std-workspace-core = { path = 'src/tools/rustc-std-workspace-core' }
rustc-std-workspace-alloc = { path = 'src/tools/rustc-std-workspace-alloc' }
rustc-std-workspace-std = { path = 'src/tools/rustc-std-workspace-std' }
libc = {path = "../libc"}
[patch."https://github.com/rust-lang/rust-clippy"]
clippy_lints = { path = "src/tools/clippy/clippy_lints" }
[dependencies]
# libc = {verion = "0.2", default-features= false, path = "../libc"}
This is the error I get:
mahto#hydlnxeng27:/local/mnt/workspace/mahto/rust$ ./x.py build --config config.toml src/libstd 2>&1 | tee build.log
Updating only changed submodules
Submodules updated in 0.04 seconds
error: failed to parse manifest at `/local/mnt/workspace/mahto/rust/Cargo.toml`
Caused by:
virtual manifests do not specify [dependencies]
failed to run: /local/mnt/workspace/mahto/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path /local/mnt/workspace/mahto/rust/src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:00
After commenting-out the dependencies section in Cargo.toml, I get this new error:
error[E0433]: failed to resolve: unresolved import
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `libc`.

nixos: my custom package derivation fails on `cargo build`

I'm writing a package derivation to install kryptco/kr and it fails on cargo build phase.
kryptco/kr has a submodule kryptco/sigchain which is written by rust.
In the Makefile of kryptco/sigchain, they use the cargo web deploy command to build its submodule. My package deriation fails on this cargo web deploy phase.
These two errors were given.
error: warning: replace for the non root package will be ignored, specify replace at the workspace root:
package: /build/src/github.com/kryptco/kr/sigchain/sigchain_client/Cargo.toml
workspace: /build/src/github.com/kryptco/kr/sigchain/Cargo.toml
error: failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
[6] Couldn't resolve host name; class=Net (12)
The former error says to edit Cargo.toml and add [replace] section, but I want to avoid edit source code if I can.
What is the cause of these error?
This is my package derivation:
# Original: https://github.com/bogsen/nixos-public/blob/a0dc497eab5de528ce3006d\
36c52bc601422cf87/pkgs/krypton/default.nix
{ config, lib, pkgs, ... }: with lib; let
cfg = config.services.krypton;
cargoWeb = with pkgs; rustPlatform.buildRustPackage rec {
...
};
dependencies = with pkgs; [
cargo
emscripten
go
makeWrapper
perl
];
kr = pkgs.stdenv.mkDerivation {
name = "kr";
src = pkgs.fetchFromGitHub {
owner = "kryptco";
repo = "kr";
rev = "2.4.10";
sha256 = "1xxhlkcw2d52q1y4h40iyvq25804w7hzv0lflqnib68aps491xnj";
fetchSubmodules = true;
};
buildInputs = dependencies ++ [cargoWeb];
dontBuild = true;
postUnpack = ''
# prevent referring /homeless-shelter
export HOME=$(pwd)
# https://github.com/kryptco/kr/issues/254#issuecomment-464890476
sed -i.bak -e '8,11d' source/sigchain/Cargo.toml
export GOPATH=$(pwd)
export GOCACHE=$GOPATH/.cache/go-build
mkdir -p src/github.com/kryptco
mv source src/github.com/kryptco/kr
ln -s src/github.com/kryptco/kr source
'';
postPatch = ''
substituteInPlace Makefile --replace sudo ""
'';
makeFlags = [ "PREFIX=$(out)" ];
};
in {
config = {
nixpkgs.config.packageOverrides = pkgs: { kr = kr; };
};
}
And whole error message is here.
# use rsync so that file modifed times are only updated when the contents change
cd dashboard_yew && cargo web deploy --release --target=wasm32-unknown-emscripten && rsync --checksum --delete -r ../target/deploy/* ../target/deploy-final
error: warning: replace for the non root package will be ignored, specify replace at the workspace root:
package: /build/src/github.com/kryptco/kr/sigchain/sigchain_client/Cargo.toml
workspace: /build/src/github.com/kryptco/kr/sigchain/Cargo.toml
Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name; class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name; class=Net (12)
error: failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
[6] Couldn't resolve host name; class=Net (12)
make[1]: *** [Makefile:25: libsigchain-with-dashboard] Error 101
make[1]: Leaving directory '/build/src/github.com/kryptco/kr/sigchain'
make: *** [Makefile:71: all] Error 2
builder for '/nix/store/78r0kh34ljzgfx658f9n99f8lxydjfxy-kr.drv' failed with exit code 2
I don't think you'll get around the [replace] edit for the config files. The build failing at cargo web deploy is due to an outdated version of openssl-sys (which is discontinued). Here's how Parity fixed it. Looks like they edited the Cargo.lock file to depend on newer versions of this lib.
You need to make it a fixed-output path, for this take a look at nix-pills.

I can't compile telegram source code with NDK

I installed NDK and set the NDK path in "Project Structure" :
And then I added below codes to build.gradle:
task buildNative(type: Exec, description: 'Compile JNI source via NDK')
{
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('jni').absolutePath, // Change src/main/jni the relative path to your jni source
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
And add this code to "defauilConfig" in build.gradle :
ndk {
moduleName "TMessagesProj"
}
When I try to build an APK , I get this error :
Error:Execution failed for task ':TMessagesProj:buildNative'.
Process 'command 'C:\Users\Mehran\AppData\Local\Android\ndk\android-ndk-r12/ndk-build.cmd'' finished with non-zero exit value 2
This is the Messages Console :
make (e=2): The system cannot find the file specified.
make: *** [D:/Mehran/AndroidStudioProjects/TelegramTest/TMessagesProj/obj/local/armeabi/objs-debug/tmessages.22/./opus/src/opus_encoder.o] Error 2
make: Leaving directory `D:/Mehran/AndroidStudioProjects/TelegramTest/TMessagesProj/jni'
Sorry for my bad English.

Resources