xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.18k stars 785 forks source link

Add: Zig fetch support #4348

Open kassane opened 1 year ago

kassane commented 1 year ago

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 commented 1 year ago

I will look at it in 2.8.6

waruqi commented 12 months ago

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

kassane commented 11 months ago

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 commented 11 months ago

zig fetch seems to be just curl + unzip

I don't know what I need to support.

kassane commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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.