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

OS and ARCH #263

Closed
runeimp opened this issue Nov 27, 2017 · 10 comments
Closed

OS and ARCH #263

runeimp opened this issue Nov 27, 2017 · 10 comments

Comments

@runeimp
Copy link

runeimp commented Nov 27, 2017

It would be awesome if I could get variables that define OS_NAME=Windows, OS_VERSION_MAJOR=10, and ARCH=x86_64 on Windows 10 64-bit when launching external apps and making builds. Or to have just load Justfile.win10-x86_64 over Justfile.win10 over Justfile.win over Justfile in such a situation. This sort of feature is the main thing I've been missing in any build/task/automation tool. I could set environment variables for all of this. But that is not ideal when the OS changes or files are copied to another system by someone else that is 32-bit vs 64-bit, etc. This is the main reason I need #262 is for managing differences between os and arch versions in my Justfile. A great start would be those types of vars based on what just was compiled for. Maybe JUST_OS=Windows and JUST_ARCH=x86_64 being available while running the Justfile would be enough.

@TeddyDD
Copy link

TeddyDD commented Nov 27, 2017

On serious OS you can get this info using cli tools :P

ARCH=`uname -m`
OS_NAME=`uname -o`

Seriously - check if there is any command like this on Windows.
Personally I don't think that idea of introducing magic variables is good.

@runeimp
Copy link
Author

runeimp commented Nov 28, 2017

Just needs to be run within a Cygwin/MinGW/MSYS based terminal. So they all have uname support. But what is returned is not consistent for uname -so. Luckily they all return x86_64 for uname -m though on my test computers for Windows and Linux. Here is the output:

POSIX Layer uname -s uname -o uname -m
Cygwin CYGWIN_NT-10.0 Cygwin x86_64
Git Bash MINGW64_NT-10.0 Msys x86_64
macOS Darwin N/A x86_64
MinGW32 MINGW32_NT-10.0 Msys x86_64
MinGW64 MINGW64_NT-10.0 Msys x86_64
MSYS2 MSYS_NT-10.0 Msys x86_64
Raspian Linux GNU/Linux armv6l
Ubuntu Linux GNU/Linux x86_64

Note that macOS does not have a -o switch for uname. Also the arch/uname -m for Raspian should be armv6l in almost all cases.

So, little consistency for uname -s and some consistency for uname -o on Windows. And in the case of just all I need is to know is that it is Windows. I can write a script to handle this but it would just be so much better if just could put JUST_OS=Windows in the environment being executed. And some conditional logic support built in would be awesome. Then I could drop make entirely.

@casey
Copy link
Owner

casey commented Nov 28, 2017

I think this would be a great feature, and I would be happy to add it to just.

Detecting OS (MacOS/Linux/Windows/BSD, etc), arch (x86, x64, ARM, etc), and variants (Cygwin on windows, e.g.) reliably is a lot of work however, and there doesn't seem to be a crate out there that does this. I found os_info and os_type, but they don't do windows, and they rely on lsb_release being installed. (I have an nix box, and lsb_release isn't installed by default.)

Given all that, I think I'd like to wait for a more robust crate which does this before adding it.

@runeimp
Copy link
Author

runeimp commented Nov 28, 2017

I appreciate the work it takes to maintain things. Thanks for considering the features. Hopefully that crate will become a thing in the near future. :-)

@runeimp
Copy link
Author

runeimp commented Nov 30, 2017

For now I've written a Bash script that calls another Bash script to collect and process all that data and populates the environment with those variables and launches a subshell with that environment. I then run just and everything else from within that subshell. It works and was fun to write but it would be great not to need that solution. Just sayin'. 😄

@casey casey mentioned this issue Dec 2, 2017
@casey casey closed this as completed in #277 Dec 2, 2017
@casey
Copy link
Owner

casey commented Dec 2, 2017

Added the functions os(), arch(), and os_family(). I wrote a tiny crate to extract this info from rust's conditional compilation flags: https://github.com/casey/target hopefully this is good enough.

No OS_VERSION_MAJOR, unfortunately, since rustc doesn't provide this.

@runeimp
Copy link
Author

runeimp commented Dec 11, 2017

Thank you Casey! But unfortunately it's not working on at least the Mac and Windows build. 😞

$ cat Justfile

sys-info:
	@echo "os_family: {{os_family()}}"
	@echo "os: {{os()}}"
	@echo "arch: {{arch()}}"

$ ./macOS/just --version
just v0.3.4
$ ./macOS/just
error: Unknown start of token:
  |
4 |     @echo "os_family: {{os_family()}}"
  |                                  ^

Maybe I'm doing something wrong? I tried adding a period at the end like in your example in the readme and no change other than the addition to the period in the error output. Same error using the same Justfile on Windows 10 Pro 64-bit in Cygwin/MinGW32/MinGW64/MSYS2 all version 2.9.0.

@casey
Copy link
Owner

casey commented Dec 11, 2017

Ah, sorry, I need to cut a release with the new features. Just a sec.

@casey
Copy link
Owner

casey commented Dec 11, 2017

I just pushed 0.3.5, which has the system-info functions. The windows binaries build on Appveyor. They'll appear here once they're done building: https://github.com/casey/just/releases/tag/v0.3.5

@runeimp
Copy link
Author

runeimp commented Dec 11, 2017

LOL, thanks for jumping on that Casey. 😉

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

No branches or pull requests

3 participants