Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instructions for building on Cygwin (if possible) #628

Open
whereswaldon opened this issue Jul 20, 2022 · 14 comments
Open

Instructions for building on Cygwin (if possible) #628

whereswaldon opened this issue Jul 20, 2022 · 14 comments

Comments

@whereswaldon
Copy link

Kakoune itself supports running on Cygwin, but it isn't clear whether kak-lsp is expected to work there also or not. When I tried to build it, I got:

error log
Cloning into 'kak-lsp'...
  Installing kak-lsp v12.2.1-snapshot (C:\cygwin64\home\chris\Code\builds\configuration\kak\plugins\kak-lsp)
    Updating crates.io index
 Downloading crates ...
  Downloaded dirs-sys-next v0.1.2
  Downloaded ryu v1.0.9
  Downloaded version_check v0.9.4
  Downloaded trackable_derive v1.0.0
  Downloaded rand_chacha v0.3.1
  Downloaded str_indices v0.3.2
  Downloaded slog-stdlog v4.1.1
  Downloaded slog-term v2.9.0
  Downloaded winapi v0.3.9
  Downloaded time-macros v0.2.4
  Downloaded semver-parser v0.10.2
  Downloaded rustversion v1.0.6
  Downloaded rle-decode-fast v1.0.3
  Downloaded ropey v1.4.1
  Downloaded tinyvec_macros v0.1.0
  Downloaded serde v1.0.136
  Downloaded take_mut v0.2.2
  Downloaded strsim v0.8.0
  Downloaded slog-async v2.7.0
  Downloaded slab v0.4.5
  Downloaded textwrap v0.11.0
  Downloaded thread_local v1.1.4
  Downloaded time v0.1.43
  Downloaded unindent v0.1.8
  Downloaded whoami v1.2.1
  Downloaded tinyvec v1.5.1
  Downloaded unicode-xid v0.2.2
  Downloaded widestring v0.4.3
  Downloaded unicode-bidi v0.3.7
  Downloaded serde_json v1.0.79
  Downloaded url v2.2.2
  Downloaded aho-corasick v0.7.18
  Downloaded trackable v1.2.0
  Downloaded regex-syntax v0.6.25
  Downloaded daemonize v0.4.1
  Downloaded enum_primitive v0.1.1
  Downloaded rand v0.8.5
  Downloaded lsp-types v0.92.1
  Downloaded indoc v1.0.4
  Downloaded dirs v2.0.2
  Downloaded diffs v0.4.1
  Downloaded dirs-sys v0.3.7
  Downloaded boxfnonce v0.1.1
  Downloaded arc-swap v1.5.0
  Downloaded libflate_lz77 v1.1.0
  Downloaded jsonrpc-core v18.0.0
  Downloaded glob v0.3.0
  Downloaded quote v1.0.17
  Downloaded syn v1.0.90
  Downloaded num-traits v0.1.43
  Downloaded serde_derive v1.0.136
  Downloaded windows-acl v0.3.0
  Downloaded libc v0.2.121
  Downloaded rand_core v0.6.3
  Downloaded regex v1.5.5
  Downloaded pin-project-lite v0.2.8
  Downloaded num-traits v0.2.14
  Downloaded ppv-lite86 v0.2.16
  Downloaded once_cell v1.10.0
  Downloaded libflate v1.2.0
  Downloaded getrandom v0.2.6
  Downloaded getopts v0.2.21
  Downloaded clap v2.34.0
  Downloaded pin-utils v0.1.0
  Downloaded pest v2.1.3
  Downloaded percent-encoding v2.1.0
  Downloaded num-integer v0.1.44
  Downloaded memoffset v0.6.5
  Downloaded memchr v2.4.1
  Downloaded matches v0.1.9
  Downloaded log v0.4.16
  Downloaded lazy_static v1.4.0
  Downloaded itoa v1.0.1
  Downloaded itertools v0.10.3
  Downloaded idna v0.2.3
  Downloaded futures-util v0.3.21
  Downloaded futures-task v0.3.21
  Downloaded futures-sink v0.3.21
  Downloaded futures-macro v0.3.21
  Downloaded futures-io v0.3.21
  Downloaded futures-executor v0.3.21
  Downloaded futures-core v0.3.21
  Downloaded futures-channel v0.3.21
  Downloaded futures v0.3.21
  Downloaded form_urlencoded v1.0.1
  Downloaded field-offset v0.3.4
  Downloaded either v1.6.1
  Downloaded dirs-next v2.0.0
  Downloaded crossbeam-utils v0.8.8
  Downloaded crossbeam-channel v0.5.4
  Downloaded crc32fast v1.3.2
  Downloaded chrono v0.4.19
  Downloaded cfg-if v1.0.0
  Downloaded cfg-if v0.1.10
  Downloaded bitflags v1.3.2
  Downloaded autocfg v1.1.0
  Downloaded atty v0.2.14
  Downloaded unicode-normalization v0.1.19
  Downloaded time v0.3.9
  Downloaded pulldown-cmark v0.8.0
  Downloaded toml v0.5.8
  Downloaded sloggers v2.1.1
  Downloaded ucd-trie v0.1.3
  Downloaded vec_map v0.8.2
  Downloaded slog-kvfilter v0.7.0
  Downloaded serde_repr v0.1.7
  Downloaded unicode-width v0.1.9
  Downloaded unicase v2.6.0
  Downloaded slog-scope v4.4.0
  Downloaded term v0.7.0
  Downloaded slog v2.7.0
  Downloaded smallvec v1.8.0
  Downloaded proc-macro2 v1.0.36
  Downloaded semver v0.11.0
  Downloaded rustc_version v0.3.3
  Downloaded adler32 v1.2.0
   Compiling proc-macro2 v1.0.36
   Compiling unicode-xid v0.2.2
   Compiling syn v1.0.90
   Compiling cfg-if v1.0.0
   Compiling autocfg v1.1.0
   Compiling winapi v0.3.9
   Compiling memchr v2.4.1
   Compiling ucd-trie v0.1.3
   Compiling serde_derive v1.0.136
   Compiling serde v1.0.136
   Compiling slog v2.7.0
   Compiling libc v0.2.121
   Compiling futures-core v0.3.21
   Compiling itoa v1.0.1
   Compiling lazy_static v1.4.0
   Compiling futures-channel v0.3.21
   Compiling futures-task v0.3.21
   Compiling rustversion v1.0.6
   Compiling tinyvec_macros v0.1.0
   Compiling log v0.4.16
   Compiling crossbeam-utils v0.8.8
   Compiling futures-util v0.3.21
   Compiling futures-sink v0.3.21
   Compiling futures-io v0.3.21
   Compiling unicode-width v0.1.9
   Compiling serde_json v1.0.79
   Compiling once_cell v1.10.0
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.5
   Compiling crc32fast v1.3.2
   Compiling matches v0.1.9
   Compiling pin-project-lite v0.2.8
   Compiling version_check v0.9.4
   Compiling bitflags v1.3.2
   Compiling ryu v1.0.9
   Compiling arc-swap v1.5.0
   Compiling rle-decode-fast v1.0.3
   Compiling unicode-bidi v0.3.7
   Compiling percent-encoding v2.1.0
   Compiling regex-syntax v0.6.25
   Compiling time-macros v0.2.4
   Compiling slog-async v2.7.0
   Compiling widestring v0.4.3
   Compiling take_mut v0.2.2
   Compiling pulldown-cmark v0.8.0
   Compiling adler32 v1.2.0
   Compiling ppv-lite86 v0.2.16
   Compiling unindent v0.1.8
   Compiling boxfnonce v0.1.1
   Compiling strsim v0.8.0
   Compiling cfg-if v0.1.10
   Compiling str_indices v0.3.2
   Compiling vec_map v0.8.2
   Compiling smallvec v1.8.0
   Compiling either v1.6.1
   Compiling diffs v0.4.1
   Compiling whoami v1.2.1
   Compiling glob v0.3.0
   Compiling getrandom v0.2.6
   Compiling pest v2.1.3
   Compiling num-traits v0.2.14
   Compiling memoffset v0.6.5
   Compiling num-integer v0.1.44
   Compiling tinyvec v1.5.1
   Compiling getopts v0.2.21
   Compiling textwrap v0.11.0
   Compiling thread_local v1.1.4
   Compiling libflate_lz77 v1.1.0
   Compiling form_urlencoded v1.0.1
   Compiling unicase v2.6.0
   Compiling indoc v1.0.4
   Compiling ropey v1.4.1
   Compiling itertools v0.10.3
   Compiling rand_core v0.6.3
   Compiling semver-parser v0.10.2
   Compiling time v0.3.9
   Compiling unicode-normalization v0.1.19
   Compiling rand_chacha v0.3.1
   Compiling aho-corasick v0.7.18
   Compiling quote v1.0.17
   Compiling daemonize v0.4.1
error[E0433]: failed to resolve: could not find `unix` in `os`
  --> C:\Users\chris\.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:58:14
   |
58 | use std::os::unix::ffi::OsStringExt;
   |              ^^^^ could not find `unix` in `os`

error[E0433]: failed to resolve: could not find unix in os
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:59:14
|
59 | use std::os::unix::io::AsRawFd;
| ^^^^ could not find unix in os

Compiling slog-scope v4.4.0
error[E0432]: unresolved imports libc::fork, libc::ftruncate, libc::setgid, libc::setsid, libc::setuid, libc::umask, libc::LOCK_EX, libc::LOCK_NB
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:65:25
|
65 | c_int, close, dup2, fork, ftruncate, getpid, open, setgid, setsid, setuid, umask, write,
| ^^^^ ^^^^^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ ^^^^^ no umask in the root
| | | | | |
| | | | | no setuid in the root
| | | | no setsid in the root
| | | no setgid in the root
| | no ftruncate in the root
| no fork in the root
66 | LOCK_EX, LOCK_NB,
| ^^^^^^^ ^^^^^^^ no LOCK_NB in the root
| |
| no LOCK_EX in the root
|
help: a similar name exists in the module
|
65 | c_int, close, dup2, fork, strncat, getpid, open, setgid, setsid, setuid, umask, write,
| ~~~~~~~
help: a similar name exists in the module
|
65 | c_int, close, dup2, fork, ftruncate, getpid, open, getpid, setsid, setuid, umask, write,
| ~~~~~~
help: a similar name exists in the module
|
65 | c_int, close, dup2, fork, ftruncate, getpid, open, setgid, getpid, setuid, umask, write,
| ~~~~~~
help: a similar name exists in the module
|
65 | c_int, close, dup2, fork, ftruncate, getpid, open, setgid, setsid, getpid, umask, write,
| ~~~~~~

error[E0432]: unresolved imports libc::gid_t, libc::mode_t, libc::uid_t
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:68:16
|
68 | pub use libc::{gid_t, mode_t, uid_t};
| ^^^^^ ^^^^^^ ^^^^^ no uid_t in the root
| | |
| | no mode_t in the root
| no gid_t in the root

error[E0412]: cannot find type uid_t in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\ffi.rs:18:19
|
18 | pw_uid: libc::uid_t,
| ^^^^^ not found in libc

error[E0412]: cannot find type gid_t in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\ffi.rs:19:19
|
19 | pw_gid: libc::gid_t,
| ^^^^^ not found in libc

error[E0412]: cannot find type gid_t in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\ffi.rs:30:19
|
30 | gr_gid: libc::gid_t,
| ^^^^^ not found in libc

error[E0412]: cannot find type gid_t in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\ffi.rs:41:63
|
41 | pub unsafe fn get_gid_by_name(name: &CString) -> Optionlibc::gid_t {
| ^^^^^ not found in libc

error[E0412]: cannot find type uid_t in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\ffi.rs:51:63
|
51 | pub unsafe fn get_uid_by_name(name: &CString) -> Optionlibc::uid_t {
| ^^^^^ not found in libc

error[E0425]: cannot find value STDIN_FILENO in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:466:25
|
466 | process_stdio(libc::STDIN_FILENO, stdin)?;
| ^^^^^^^^^^^^ not found in libc

error[E0425]: cannot find value STDOUT_FILENO in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:467:25
|
467 | process_stdio(libc::STDOUT_FILENO, stdout)?;
| ^^^^^^^^^^^^^ not found in libc

error[E0425]: cannot find value STDERR_FILENO in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:468:25
|
468 | process_stdio(libc::STDERR_FILENO, stderr)?;
| ^^^^^^^^^^^^^ not found in libc

error[E0425]: cannot find function chown in crate libc
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:527:15
|
527 | libc::chown(path_c.as_ptr(), uid, gid),
| ^^^^^ not found in libc

Compiling crossbeam-channel v0.5.4
error[E0283]: type annotations needed
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:177:10
|
177 | impl<'a> From<&'a str> for User {
| ^^^^^^^^^^^^^ cannot infer type for enum User
|
note: multiple impls satisfying User: From<&'a str> found
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:177:1
|
177 | impl<'a> From<&'a str> for User {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
183 | impl From<uid_t> for User {
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0283]: type annotations needed
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:196:10
|
196 | impl<'a> From<&'a str> for Group {
| ^^^^^^^^^^^^^ cannot infer type for enum Group
|
note: multiple impls satisfying Group: From<&'a str> found
--> C:\Users\chris.cargo\registry\src\github.com-1ecc6299db9ec823\daemonize-0.4.1\src\lib.rs:196:1
|
196 | impl<'a> From<&'a str> for Group {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
202 | impl From<gid_t> for Group {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0283, E0412, E0425, E0432, E0433.
For more information about an error, try rustc --explain E0283.
error: could not compile daemonize due to 15 previous errors
warning: build failed, waiting for other jobs to finish...
error: failed to compile kak-lsp v12.2.1-snapshot (C:\cygwin64\home\chris\Code\builds\configuration\kak\plugins\kak-lsp), intermediate artifacts can be found at C:\cygwin64\home\chris\Code\builds\configuration\kak\plugins\kak-lsp\target
DONE

If this just isn't supported, that's totally fine. I do think it would be good to document that somewhere in the README though. Thanks!

@krobelus
Copy link
Member

Sure, lemme dust off my windows box.
If it's just about daemonize then a fix should be straighforward. We only use it to spawn the long-lived controller process.

@whereswaldon
Copy link
Author

I can't be sure that's the only problem, but I hope it is. Thank you for looking into it!

@krobelus
Copy link
Member

Ok for cygwin we'd need to

  1. replace unix sockets (see UnixStream) with another IPC mechanism (TCP?) on windows
  2. daemonize can probably just be dropped on windows
  3. replace/drop missing libc functions (these should be easy)
  • mkstemp
  • mkfifo
  • umask

We should probably support cygwin, though I wonder if anyone would use that (does it have an advantage over WSL?).

I think READMEs usually only list supported platforms, because there are many more unsupported ones. Though a small note about prominent unsupported ones like Cygwin won't hurt.

@whereswaldon
Copy link
Author

Allow me to explain my use-case, and you can decide for yourself whether it's legitimate enough to warrant the effort. I work on a desktop application in Go that targets Linux, macOS, and Windows. I do most of my development work from Linux in Kakoune, where support is great. However, sometimes I need to write code that is platform-specific for any of the three platforms. On macOS, kakoune still works great. On Windows, I can run kak in WSL, but I encounter problems:

  • constant problems with trying to share a directory between WSL and the windows host system (I need to compile for Windows, after all, which is best done outside of WSL)
  • gopls initializes for Linux because WSL is Linux, meaning that I fight a mostly-useless LSP integration when working on the Windows platform code.

I decided to try Cygwin because Go can properly target GOOS=windows there, but Kakoune supports it as a runtime. I also think that I'll have fewer problems with git directory state this way.

One can certainly argue that this is a problem with gopls, as it doesn't seem to support running for GOOS values other than the current OS, but I'd also need to configure a cross-compiler toolchain for native code within WSL, which is a second huge pain.

So... If Cygwin were supported, it would benefit me when having to write code that actually targets Windows, as I don't need to cross-compile said code from within WSL. However, it certainly sounds like it's work for y'all, and I'm not in a position to help other than to test. If you decide the cost/benefit isn't worth it, I'd be happy for it to be documented anywhere. I searched the entire repo for references to Cygwin before opening this issue, and I couldn't find anything definitive about its support.

@krobelus
Copy link
Member

krobelus commented Jul 22, 2022

thanks, that sounds like a good use case.
Adding (at least hacky) Cygwin support shouldn't be much work, I'll get access to my windows machine soon (my VM is too slow).

  • constant problems with trying to share a directory between WSL and the windows host system

I'd keep everything in WSL and only place the output binary somewhere windows can access

One can certainly argue that this is a problem with gopls, as it doesn't seem to support running for GOOS values other than the current OS,

After some random initial failures, at least build tags seem to work fine for me on Linux:

$ cat go.mod 
module example.com/m

go 1.18
$ cat foo_linux.go
//go:build linux

package main

func foo() {
}
$ cat foo_windows.go 
//go:build windows

package main

func foo() {
}
$ cat main.go 
package main

func main() {
	foo()
}
$ GOOS=windows kak main.go 
# lsp-definition will jump to the windows version

but I'd also need to configure a cross-compiler toolchain for native code within WSL,

you mean for non-Go code? Go cross compilation should be pretty simple

@whereswaldon
Copy link
Author

thanks, that sounds like a good use case. Adding (at least hacky) Cygwin support shouldn't be much work, I'll get access to my windows machine soon (my VM is too slow).

  • constant problems with trying to share a directory between WSL and the windows host system

I'd keep everything in WSL and only place the output binary somewhere windows can access

I failed to add that this project has C dependencies because it directly interfaces with Windows APIs. Because of that, I need to compile Go, C, and C++. Cross-compiling from within WSL is a big pain, hence my desire to work outside of it.

One can certainly argue that this is a problem with gopls, as it doesn't seem to support running for GOOS values other than the current OS,

Today I learned that gopls honors GOOS. I couldn't find any documentation about that at all. Perhaps I just didn't look in the right places?

Anyway, I'd still need to get a functional cross-compilation toolchain within WSL for running gopls with GOOS=windows to actually work. For projects without native dependencies, the situation is much easier. :D

Thanks for the thorough investigation on this!

@krobelus
Copy link
Member

krobelus commented Jul 23, 2022

Ok I got kak-lsp+gopls running on Cygwin, see the cygwin branch.
(Some workarounds are pretty dirty and I disabled some features on windows for now.)

On my Windows VM, it is unusably slow (while plain kak is fine). Can you test if it's fast enough for you?
If not, there's a pretty easy way to speed things up, see #553 or https://github.com/tomKPZ/pykak/.
To give some figures: on my linux system echo nop | kak -p session takes 2.8 milliseconds whereas on the Windows VM it's > 100 milliseconds.

BTW to run kak directly from a git worktree, we need to enable symlink support windows and git.
I used choco to install most packages via cygwin, so for example choco install gcc-g++ --source=cygwin. For rust/go I used the official installers. Rust requires installing Visual Studio, rustup has pretty nice instructions.

@whereswaldon
Copy link
Author

I'll give this a shot on Monday. Thank you!

@whereswaldon
Copy link
Author

Sorry, I haven't been able to try this yet. I think I will have a good chance tomorrow morning though.

@whereswaldon
Copy link
Author

whereswaldon commented Jul 27, 2022

Okay, running with kak-lsp enabled is unusably slow. With windows in which lsp is enabled open, there's multi-second latency on every keystroke. I'm not sure how to productively time the various background interactions though.

In cygwin I get this from your timing example:

$ time (echo nop | kak -p ses)

real    0m0.029s
user    0m0.000s
sys     0m0.015s

So I think non-virtualized windows is an order or magnitude slower than linux, but not so bad as your VM.

BTW to run kak directly from a git worktree, we need to enable symlink support windows and git.

I'm not certain that I understand what you mean about running directly from a worktree. Can you elaborate?

Thanks again for investigating this! I really appreciate the effort you've put in.

@krobelus
Copy link
Member

Alright. Maybe the overhead comes from spawning shell and kak processes, we can try to get rid of that

I'm not certain that I understand what you mean about running directly from a worktree. Can you elaborate?

If you run /path/to/kakoune/src/kak (in lieu of installing it with make install)

@whereswaldon
Copy link
Author

If you run /path/to/kakoune/src/kak (in lieu of installing it with make install)

I did install it, but I also enabled symlinks. Hopefully it's a nonissue. :D

@krobelus
Copy link
Member

improving cygwin performance (by removing shell calls) is still on the roadmap but it's a large change, I need to set aside time for that

@whereswaldon
Copy link
Author

I would sincerely appreciate the work if you chose to do it, but I'm also only one person asking for this. I understand if it's not a priority. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants