Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Jun 7, 2024
0 parents commit e351165
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and test the esy package

on:
- push

jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- macos-13jk
- macos-latest
- ubuntu-latest
- windows-latest

runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3

- name: Install esy, verdaccio and esy-package
run: npm install -g esy esy-package

- name: Run end-to-end tests on the package
run: DEBUG=bale*,verdaccio* esy-package
shell: bash
env:
SHELL: "bash.exe" # HACK!! For some weird reason, $SHELL in Github actions' Windows' bash shell doesn't set this environment variable. We rely on it to figure if path normalisation is necessary on Gitbash Windows

- uses: actions/upload-artifact@v3
with:
name: release
path: package.tar.gz
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*~
node_modules
_esy
_esy-package
.log
package.tar.gz
package.tgz
verdaccio-storage
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//localhost:4873/:_authToken="+vVrDzq8gudTDDEoQOS+PQ=="
139 changes: 139 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
![Build and test the esy
package](https://github.com/ManasJayanth/esy-packages-template/workflows/Build%20and%20test%20the%20esy%20package/badge.svg)

# esy-zlib

`esy-zlib` is sample package, [`zlib`](https://www.zlib.net/), packaged for [`esy`](https://esy.sh/).

## Why
`esy` can not only fetch and install Reason and OCaml libraries and tools,
but also those written in C. This extends reproducibility benefits to
packages written in C, like `skia`, `libffi`, `pkg-config`
etc. Users don't have to install them separately, nor have to worry if
they have installed the correct version. Read more at the docs about
[benefits for opting for esy packages](https://esy.sh#TODO).

## How to use `esy-zlib`?

`esy-zlib` can be used from both NPM and directly from Github.

### From NPM

`esy-zlib` is deployed on NPM can be found
[here](https://www.npmjs.com/package/TODO).

You can simply run `esy add esy-zlib` to install it, or specify it in
`package.json` and run `esy`.

```diff
{
"dependencies": {
+ "esy-zlib": "*"
}
}
```

### Directly from Github

```json
{
"dependencies": {
"esy-zlib": "esy-packages/esy-zlib"
}
}
```

i.e. `<GITHUB_ORG or USERNAME>/<REPO NAME>`

To use a specific commit,

```diff
"dependencies": {
+ "esy-zlib": "esy-packages/esy-zlib#<commit hash>"
}
```

## How to package for esy?

### For the experienced

**The gist**
Specify the configure and build commands in `esy.build` property of
`esy.json` and the install step in `esy.install`. If the package
builds "in source", set `esy.buildsInSource` property to `true`. Use
`$cur__install` environment variable to set the install location.

See [docs](TODO) for reference.

The CI will take care of fetching the sources and creating an NPM
package for you. See [script.js](TODO) to see how it works.

You can download it or auto publish via CI.

### For beginners

> Note: you'll need Node.js for this tutorial. If you're experienced
> with bash, you can use it instead.
Fundamentally, packaging for esy works like in other Linux distros,
except ofcourse, such that packages become available on MacOS and
Windows too.

You would typically have to specify the instructions to build the
package in the `esy.json`. For example, everyone's favourite http
tool, [curl](https://curl.se/), needs the following instructions ([as
described on their website](https://curl.se/docs/install.html))

```sh
./configure
make
make install
```

Many packages have similar instructions!

Configure and build steps are specified in the `esy.build` property in
the `esy.json` and install steps in `esy.install`. Example,

```json
{
"esy": {
"build": [
"./configure",
"make"
],
"install": [
"make install"
]
}
}
```


## Testing and making sure the package works as expected

To test if the package works, we recommend an end-to-end test by
publishing it to local
[`verdaccio`](https://github.com/verdaccio/verdaccio), and using the
package with a `package.json` or `esy.json` depends on it.

```json
{
"dependencies": {
esy-zlib": "*"
}
}
```

And pointing `esy` to the local npm registry

```sh
esy i --npm-registry http://localhost:4873
esy b
```

If the package is a library, it's a good idea to write a small program
to actually check if the library works. Referring how the
corresponding package is being tested in Homebrew or Arch Linux.

Checkout [ci-test.sh](./ci-test.sh) for reference, used on the CI.
3 changes: 3 additions & 0 deletions esy-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
esy.lock
_esy
node_modules
1 change: 1 addition & 0 deletions esy-test/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See [Readme in the root][../Readme.md#testing-and-making-sure-package-works-as-expected]
8 changes: 8 additions & 0 deletions esy-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"esy": {
"build": "ls -R #{esy-zlib.lib}"
},
"dependencies": {
"esy-zlib": "*"
}
}
42 changes: 42 additions & 0 deletions esy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "esy-zlib",
"version": "1.3.1000",
"description": "zlib packaged for esy",
"source": "https://zlib.net/zlib-1.3.1.tar.gz#sha256:9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23",
"override": {
"exportedEnv": {
"CFLAGS": {
"scope": "global",
"val": "-I#{self.install / 'include'} $CFLAGS"
},
"LDFLAGS": {
"scope": "global",
"val": "-L#{self.lib} -lz $LDFLAGS"
},
"PKG_CONFIG_PATH": {
"scope": "global",
"val": "#{self.lib / 'pkgconfig' : $PKG_CONFIG_PATH }"
},
"Z_LIB_PATH": {
"val": "#{self.lib}",
"scope": "global"
}
},
"buildEnv": {
"CHOST": "#{os == 'windows' ? 'x86_64-w64-mingw32': '' }",
"CFLAGS": "-fPIC -O2"
},
"build": [
[
"bash",
"-c",
"./configure --prefix=$cur__install #{os == 'windows' ? '--uname=cygwin' : ''}"
],
"make",
"make test"
],
"install": "make install",
"buildsInSource": true,
"dependencies": {}
}
}

0 comments on commit e351165

Please sign in to comment.