Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

macros in Build Scripts #78

Open
jwerle opened this issue Jun 22, 2020 · 10 comments · Fixed by #97
Open

macros in Build Scripts #78

jwerle opened this issue Jun 22, 2020 · 10 comments · Fixed by #97
Assignees
Labels
enhancement New feature or request question Further information is requested
Milestone

Comments

@jwerle
Copy link
Member

jwerle commented Jun 22, 2020

Currently, there is no way to depend on a library or source code that needs to be built outside of the ZZ build process. Listing source files as cobjects is not enough when the library source may require the traditional ritual of autoconf, configure, make, make install (with prefix).

An example of this are the libuv bindings over here

When a consumer of this module uses it, it will break because there is no way to build the libuv submodule before the ZZ module is built.

@aep What are your thoughts on supporting build scripts? We could have a [scripts] section of the zz.toml file similar to that of npm-scripts or something similar to Rust's Build Scripts.

@jwerle jwerle added enhancement New feature or request question Further information is requested labels Jun 22, 2020
@jwerle jwerle self-assigned this Jun 22, 2020
@aep
Copy link
Collaborator

aep commented Jun 22, 2020

i'm generally reluctant to add generic build scripts because they just delay the inevitable problem.

if a dependency is not portable C code, you'll end up with difficult to maintain build steps no matter what. For example libuv probably wants to create a static lib, but how do you tell it to enable ubsan? you could pass a bunch of CFLAGS down there, but you'll just end up rewriting their build system anyway, so you might as well just add the cfiles.

However, if you still feel like this is the better path, i'd suggest to just straight up copy what rust does. It's not great, but at least its flexible enough that it does allow a library to solve these issues.

@jwerle
Copy link
Member Author

jwerle commented Jun 22, 2020

That is a great point. It is actually possible to achieve this now, without code change by using macros!

I created an arbitrarily named file called src/build.zz:

using <unistd.h>::{ getcwd }
using <stdio.h>::{ stdout, fclose, sprintf }
using <stdlib.h>::{ system }

macro build() {
  char mut cwd[65335];
  char mut command[65335];
  fclose(stdout);
  getcwd(cwd, sizeof(cwd));
  sprintf(command, "touch %s/foo", cwd);
  system(command);
}

fn init() {
  @build();
}

@aep
Copy link
Collaborator

aep commented Jun 22, 2020

wow thats really smart, i love it

@jwerle
Copy link
Member Author

jwerle commented Jun 22, 2020

hell yeah, okay closing!

@jwerle jwerle closed this as completed Jun 22, 2020
@aep
Copy link
Collaborator

aep commented Jun 22, 2020

actually, it doesnt let you add cobjects or ldflags to the linker. that's probably something you'll need.

i guess we could expand the macro AST to add these.

@aep aep reopened this Jun 22, 2020
@aep
Copy link
Collaborator

aep commented Jun 22, 2020

i.e. by adding a generic way to add things to cobjects, ldflags and cflags from regular statements https://github.com/zetzit/zz/blob/master/src/zz.pest#L295

then macro can expand to these statements.

@jwerle
Copy link
Member Author

jwerle commented Jun 22, 2020

hmm, interesting! what would that look like?

@aep
Copy link
Collaborator

aep commented Jun 22, 2020

pp is also a good candidate to add this stuff to https://github.com/zetzit/zz/blob/master/src/zz.pest#L136

something like

#LDFLAGS: -luv

struct uv  {
...
}

@aep
Copy link
Collaborator

aep commented Jul 20, 2020

this is now implemented in #97 . it merely lacks support for macros to close this

@jwerle jwerle added this to the Build Scripts milestone Jul 20, 2020
@jwerle jwerle linked a pull request Jul 20, 2020 that will close this issue
@aep aep closed this as completed in #97 Jul 20, 2020
@aep aep reopened this Jul 20, 2020
@aep
Copy link
Collaborator

aep commented Jul 20, 2020

this is not closed. still lacking macro support to enable pkgconfig and other configuration tests

@aep aep changed the title Build Scripts macros in Build Scripts Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants