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

Add: Zig fetch support #4348

Open
kassane opened this issue Nov 1, 2023 · 7 comments
Open

Add: Zig fetch support #4348

kassane opened this issue Nov 1, 2023 · 7 comments

Comments

@kassane
Copy link

kassane commented Nov 1, 2023

Is your feature request related to a problem? Please describe.

Hi @waruqi,

This is also the case with pkg-managers for other languages such as dub, conan, vcpkg, cargo...

zig 0.12.0-dev already has a fetch command to download packages and print the hash (multihash - sha256-2)

progress to release: https://github.com/ziglang/zig/milestone/23

Help:

fetch            Copy a package into global cache and print its hash

Wrong command:

$> zig fetch git+https://github.com/xmake-io/xmake                                                    
error: url field is missing an explicit ref
    note: try .url = "github.com/xmake-io/xmake#1a53bc8550214990846409c31bc1e96bdedc49f4",

Command fixed:

$> zig fetch git+https://github.com/xmake-io/xmake#1a53bc8550214990846409c31bc1e96bdedc49f4
122040fb6a7b8a56d46458edad58fd43525b6e8f964f60816d1f516f36dfd0817abb
# OR
$> zig fetch https://github.com/xmake-io/xmake/archive/1a53bc8550214990846409c31bc1e96bdedc49f4.tar.gz

$> ls $HOME/.cache/zig/p/122040fb6a7b8a56d46458edad58fd43525b6e8f964f60816d1f516f36dfd0817abb 
CHANGELOG.md  CODE_OF_CONDUCT.md  CONTRIBUTING.md  LICENSE.md  NOTICE.md  README.md  README_zh.md  configure  core  scripts  tests  xmake

Describe the solution you'd like

I would suggest adding support for zig fetch without the need for build.zig and build.zig.zon.

New zig env get:

$> zig env
{
 "zig_exe": "/home/kassane/zig/0.12.0-dev.1372+8457439a8/files/zig",
 "lib_dir": "zig/0.12.0-dev.1372+8457439a8/files/lib",
 "std_dir": "zig/0.12.0-dev.1372+8457439a8/files/lib/std",
 "global_cache_dir": "/home/kassane/.cache/zig",
 "version": "0.12.0-dev.1372+8457439a8",
 "target": "x86_64-linux.6.5.9...6.5.9-gnu.2.38",
 "env": {
  "ZIG_GLOBAL_CACHE_DIR": null,
  "ZIG_LOCAL_CACHE_DIR": null,
  "ZIG_LIB_DIR": null,
  "ZIG_LIBC": null,
  "ZIG_BUILD_RUNNER": null,
  "ZIG_VERBOSE_LINK": null,
  "ZIG_VERBOSE_CC": null,
  "ZIG_BTRFS_WORKAROUND": null,
  "CC": null,
  "NO_COLOR": null,
  "XDG_CACHE_HOME": null,
  "HOME": "/home/kassane"
 }
}

Overwrite ZIG_GLOBAL_CACHE_DIR to xmake

$> xmake create -l zig zig-pkg
$> cd zig-pkg
$> ZIG_GLOBAL_CACHE_DIR=$PWD/.xmake  zig fetch git+https://github.com/xmake-io/xmake#1a53bc8550214990846409c31bc1e96bdedc49f4
$>  ls .xmake/p/122040fb6a7b8a56d46458edad58fd43525b6e8f964f60816d1f516f36dfd0817abb 
CHANGELOG.md  CODE_OF_CONDUCT.md  CONTRIBUTING.md  LICENSE.md  NOTICE.md  README.md  README_zh.md  configure  core  scripts  tests  xmake

Describe alternatives you've considered

No response

Additional context

References

@waruqi
Copy link
Member

waruqi commented Nov 1, 2023

I will look at it in 2.8.6

@waruqi waruqi added this to the v2.8.6 milestone Nov 1, 2023
@waruqi
Copy link
Member

waruqi commented Nov 28, 2023

Can you provide a full project example with zig packages? and provide the whole fetch commands or makefile.

@kassane
Copy link
Author

kassane commented Nov 29, 2023

a full project example with zig packages? and provide the whole fetch commands or makefile.

e.g:
https://github.com/kassane/cppfront-zigbuild (need zig v0.12.0-dev - uses zig-pkg [git support])
get pkg: https://github.com/kassane/cppfront-zigbuild/blob/120c89f77ea1c634e89a8c94f1ef3b8201efb10f/build.zig#L7-L10

Use makefile:

# default: $HOME/.cache
# Set the output directory for Zig packages (overwrited)
export ZIG_GLOBAL_CACHE_DIR := $(PWD)/.zig-pkg

# Fetch the package and get its hash
PKG_HASH := $(shell zig fetch git+https://github.com/hsutter/cppfront#789cd382ed4c2fb1a9e306e73b6876228d22207d)

# Build the executable
cppfront: $(PWD)/.zig-pkg/p/$(PKG_HASH)/source/cppfront.cpp
	clang++ -std=c++20 -O3 -o cppfront -I$(PWD)/.zig-pkg/p/$(PKG_HASH)/include -I$(PWD)/.zig-pkg/p/$(PKG_HASH)/source $(PWD)/.zig-pkg/p/$(PKG_HASH)/source/cppfront.cpp

# Target to fetch the package
fetch:
	zig fetch git+https://github.com/hsutter/cppfront#789cd382ed4c2fb1a9e306e73b6876228d22207d

# Clean the build
clean:
	rm -f cppfront

# PHONY targets to prevent conflicts with filenames
.PHONY: fetch clean

@waruqi
Copy link
Member

waruqi commented Dec 12, 2023

zig fetch seems to be just curl + unzip

I don't know what I need to support.

@kassane
Copy link
Author

kassane commented Dec 12, 2023

zig fetch seems to be just curl + unzip

zig-pkg is WiP, can get more features later! It may seem like it, although it doesn't require git installed to work.

Can you guarantee the same result on all platforms (Win|Unix-like) without zig fetch sample?

@waruqi
Copy link
Member

waruqi commented Dec 13, 2023

Maybe I should wait for zig-pkg to support it again.

Can you guarantee the same result on all platforms (Win|Unix-like) without sample?zig fetch

?

@kassane
Copy link
Author

kassane commented Dec 13, 2023

Maybe I should wait for zig-pkg to support it again.

Ok.

Currently, 0.11.0 zig-pkg only supports projects that have build.zig to be built.

Version 0.12.0 allows you to get packages without build.zig and just use them in your project.

And CMake's idea would be to support it without the need for build.zig and build.zig.zon.

?

Sorry! I asked about alternatives.

@waruqi waruqi removed this from the v2.8.6 milestone Dec 13, 2023
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

2 participants