Rust `unresolved import` on third party library - import

I want to compile a simple rust program using a third party library named warp:
[package]
name = "hello-world-warp"
version = "0.1.0"
[dependencies]
warp = "0.1.18"
In src/main.rs:
use warp::{self, path, Filter};
fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run(([127, 0, 0, 1], 3030));
}
When I run cargo build I see it download warp and lots of transitive dependencies, then I get the errors:
Compiling hello-world-warp v0.1.0 (<path>) error[E0432]: unresolved import `warp`
--> src/main.rs:3:12
|
3 | use warp::{self, path, Filter};
| ^^^^ no `warp` in the root
error: cannot find macro `path!` in this scope
I've gone through various docs on modules and crates. What am I doing wrong in this simple scenario?

The example you copied uses a syntax that works in the most recent edition of Rust, but you've accidentally set your Rust to emulate an old "2015" version of the language.
You must add:
edition = "2018"
to your Cargo.toml's [package] section.
When starting new projects, always use cargo new. It will ensure the latest edition flag is set correctly.

Related

How to add Babel support for nullishCoalescingOperator to vue project?

In my Vue-CLI project, when I tried using the ?? operator, I got this error:
Syntax Error: SyntaxError: /Users/stevebennett/odev/freelancing/v-map/src/components/Map.vue: >Support for the experimental syntax 'nullishCoalescingOperator' isn't currently enabled (30:29):
...
Add #babel/plugin-proposal-nullish-coalescing-operator (https://git.io/vb4Se) to the 'plugins' section of your Babel config to enable transformation.
I installed #babel/plugin-syntax-nullish-coalescing-operator (its name seems to have changed), added it to my babel.config.js:
module.exports = {
presets: ['#vue/app'],
plugins: ['#babel/plugin-syntax-nullish-coalescing-operator'],
};
Now the error message seems to have gone backwards, no reference to the operator name at all:
Module parse failed: Unexpected token (39:35)
You may need an appropriate loader to handle this file type.
| case 8:
| points = _context.sent;
console.log(sheetID ?? 37);
What am I doing wrong?
For me, the #babel/plugin-syntax-nullish-coalescing-operator plugin would not work, which is the one you are using.
I had to use the #babel/plugin-proposal-nullish-coalescing-operator plugin which is the one that the error message suggests you use.
Additionally, I noticed this on the page for the #babel/plugin-syntax-nullish-coalescing-operator plugin:
I can't say for sure if this will fix your problem, but it certainly fixed mine

Could not find openssl in backend

Error I get:
error[E0433]: failed to resolve: could not find `openssl` in `backend`
--> ...\src\...\swagger-0.12.1\src\connector.rs:41:34
|
41 | native_tls::backend::openssl::TlsConnectorBuilderExt::from_openssl(ssl);
| ^^^^^^^ could not find `openssl` in `backend`
error[E0433]: failed to resolve: could not find `openssl` in `backend`
--> ...\swagger-0.12.1\src\connector.rs:85:34
|
85 | native_tls::backend::openssl::TlsConnectorBuilderExt::from_openssl(ssl);
| ^^^^^^^ could not find `openssl` in `backend`
Compiling hyper v0.2.1
error: expected identifier, found `"rustc-serialize"`
--> ...\hyper-0.2.1\src\lib.rs:129:14
|
129 | extern crate "rustc-serialize" as serialize;
| ^^^^^^^^^^^^^^^^^ expected identifier
Generated a server stub user swagger. Ran into issues where cargo couldn't find openssl, giving an error like 'custom build something openssl-sys 0.9.24'. This was a known issue and I overcame it by downloading vcpkg, and using vcpkg to download openssl. Then using environment variables to point to the download folder so cargo could use openssl. But now the error seems to be that openssl doesn't exist in backend?
It also seems to specific to windows, any ideas?
Tried changing the version of native-tls to the most up to date version but it doesn't seem to have an affect at all. It looks like swagger's dependencies need updating but I literally just generated this stub...
You've landed on a flaw from the Rust documentation tools; it picks up what is in a package, but doesn't show the limits.
The backend module definition is defined as:
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod security_framework;
#[cfg(target_os = "windows")]
pub mod schannel;
#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
pub mod openssl;
In other words, the situation is the following:
If you are on linux (i.e. not macOS, not windows, not iOS), then openssl is available
If you are on windows, then schannel is available
If you are on MacOS or iOS security_framework is available
You should, however, not be trying to target a specific backend, as this defeats the purpose of the library. Instead of importing native_tls::backend::openssl::TlsConnectorBuilderExt, import native_tls::TlsConnectorBuilder and let it decide what backend you need.
This may be easier said than done, however, since by the looks of your error this is caused by a third-party library, which indicates that it was only tested on Linux.

Weird haskell stack build exit failure: cairo requires cairo?

While experimenting with Haskell using the Stack Tool to build a gtk+ gui by enhancing the Main.hs code from the new-template as follows:
module Lib
( someFunc
) where
import Control.Monad
import Control.Monad.IO.Class
import Data.IORef
import Graphics.UI.Gtk hiding (Action, backspace)
someFunc :: IO ()
someFunc = do
void initGUI
window <- windowNew
widgetShowAll window
mainGUI
I am encountering the following weird error in which the target seems to be searching for a later version of itself:
>stack build
glib-0.13.6.0: configure
cairo-0.13.5.0: configure
Progress 2/6
-- While building package cairo-0.13.5.0 using:
/tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/setup --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 configure --with-ghc=/home/gd/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc --with-ghc-pkg=/home/gd/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc-pkg --user --package-db=clear --package-db=global --package-db=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/pkgdb --libdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/lib --bindir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/bin --datadir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/share --libexecdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/libexec --sysconfdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/etc --docdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --htmldir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --haddockdir=/home/gd/.stack/snapshots/x86_64-linux/lts-12.19/8.4.4/doc/cairo-0.13.5.0 --dependency=Cabal=Cabal-2.2.0.1 --dependency=array=array-0.5.2.0 --dependency=base=base-4.11.1.0 --dependency=bytestring=bytestring-0.10.8.2 --dependency=gtk2hs-buildtools=gtk2hs-buildtools-0.13.4.0-DsVNfQpDbxJKtQSA2HZlGY --dependency=mtl=mtl-2.2.2 --dependency=text=text-1.2.3.1 --dependency=utf8-string=utf8-string-1.0.1.1-LRSjvSC6FZkKPp48Qszoj8
Process exited with code: ExitFailure 1
Logs have been written to: /home/gd/Projects/hgtk/.stack-work/logs/cairo-0.13.5.0.log
[1 of 2] Compiling Main ( /tmp/stack3691/cairo-0.13.5.0/Setup.hs, /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/Main.o )
[2 of 2] Compiling StackSetupShim ( /home/gd/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/StackSetupShim.o )
Linking /tmp/stack3691/cairo-0.13.5.0/.stack-work/dist/x86_64-linux/Cabal-2.2.0.1/setup/setup ...
Configuring cairo-0.13.5.0...
setup: The pkg-config package 'cairo' version >=1.2.0 is required but it could
not be found.
Thanks in advance for any assistance.
cairo-0.13.5.0 seems to be the haskell bindings to the cairo C library (just a guess). The cairo C library's current version is 1.16 and it is "beyond 1.0" for years already. So yes, indeed, cairo requires cairo. But this is "haskell cairo bindings requires cairo C library".

Failing to compile MonoGame on Boo compiler

SharpDevelop compiles fine, but trying to compile through booc doesn't work.
Boo Compiler version 0.9.4.9 (CLR 2.0.50727.8000)
Program.boo(4,8): BCE0021: Namespace 'Microsoft.Xna.Framework' not found, maybe
you forgot to add an assembly reference?
booc -resource:"C:\test\" Program.boo , the command used in Windows cmd tool.
Thank you. Alisa.
Sharpdevelop most likely already references the libraries to the compiler for you. What that means is, when you manually invoke the booc command line compiler, you will have to tell the compiler where exactly the MonoGame library is. I haven't been able to check myself yet, but I did have a quick look at the command lines and the Boo source code, and I think you have to do the following:
-lib:C:/Path/To/MonoGame/Libraries
This will tell the compiler where to look for additional libraries.
The next thing you should then do is add the libraries you want, eg:
-r:Microsoft.Xna.Framework.dll,Microsoft.Xna.Framework.Game.dll
Add these two additional compiler options to your command line and I think it should work.
I haven't compiled this myself really, because I found it rather tedious. Instead, I decided to create my own build script in Boo itself in order to compile my Boo programs. That way I still had to add the library path and reference the libraries, as in the following snippet:
def CompileEngine() as bool:
"""Compiles the engine and puts it in ./lib/SpectralEngine.dll"""
compiler = BooCompiler()
compiler.Parameters.Pipeline = CompileToFile()
compiler.Parameters.OutputType = CompilerOutputType.Library
compiler.Parameters.Ducky = true
compiler.Parameters.LibPaths.Add("./lib")
compiler.Parameters.OutputAssembly = "./lib/SpectralEngine.dll"
# Add libraries.
compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("OpenTK.dll"))
compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("NAudio.dll"))
compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("Boo.Lang.dll"))
compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("Boo.Lang.Parser.dll"))
compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("Boo.Lang.Compiler.dll"))
# Take all boo files from the Engine source directory.
files = (Directory.GetFiles(Directory.GetCurrentDirectory() + """/src/Engine""", "*.boo", SearchOption.AllDirectories)
.Where({file as string | return not file.Contains("Gwen")})) # Filter out old GWEN files.
for file in files:
print "Adding file: " + file
compiler.Parameters.Input.Add(FileInput(file))
print "Compiling to ./lib/SpectralEngine.dll"
context = compiler.Run()
if context.GeneratedAssembly is null:
print "Failed to compile:\n" + join(e for e in context.Errors, "\n")
return false
else:
return true
I've put two of these build scripts at here and here. It's perhaps a bit overkill for you, though.

commands.py: name 'play_command' is not defined

I am new to Play and GWT and following the documentation given here. But I see the following errors:
bash-3.2$ play deps test-gwt
!! Error whileloading /opt/play-1.2.1/modules/gwt-1.0/commands.py: name 'play_command' is not defined
~
~ Resolving dependencies using /Users/Harit/Documents/personal/projects/test-gwt/conf/dependencies.yml,
~
~ play->gwt 1.0 (from playLocalModules)
~
~ Installing resolved dependencies,
~
~ modules/gwt-1.0 -> /opt/play-1.2.1/modules/gwt-1.0
~
~ Done!
I see that there is a corresponding bug here, and status is fix_commited, but I don't know what shall I do?
Isn't it just because play-gwt module is not compatible with play 1.2 ?
Apparently this module is quite old and not very active and command syntax has changed in version 1.1.x or something like that.
Before, you wrote commands.py like that:
...
if play_command.startswith('gwt:'):
...
and now, it is like that:
...
MODULE = "secure"
COMMANDS = ["secure:", "secure:ov", "secure:override"]
HELP = {
"secure:": "Show help for the secure module",
"secure:override": "Override the CSS, login or layout"
}
def execute(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")
if command == 'secure:':
...
In my opinion, the modification is really light so you can either ask the module owner if he would accept to do it or even do it by yourself ;)
There is also a GWT2 module which seems much more active: http://www.playframework.org/modules/gwt2 (apparently no new version since last october but the github project shows very recent commits with play1.2 support)