4 ms·
Consider also what including a file means. Ok, so you read from a file on the filesystem, but what about custom filesystems? I played around with this idea a w
by camel-cdr 3y ago
Consider also what including a file means. Ok, so you read from a file on the filesystem, but what about custom filesystems?
I played around with this idea a while ago and build a user space filesystem that executes the file names with the shell [0] (it needs a bit of a custom syntax to express characters that aren't allowed in filenames)
$ ./execfs mnt # or make mount
$ cat 'mnt/(uname)'
Linux
$ cat "mnt/unique text(seq 10 | awk '{c+=\$1}END{print(c)}')unique text"
55
$ fusermount -u mnt # or make umount
This allows you to basically do anything you want at compiletime with any C compiler:
$ cat examples.h
char seed[8] = {
#include "mnt/(head -c 8 /dev/urandom | xxd -i)"
};
double pi_squared =
#include "mnt/(python -c @;import math;print(math.pi * math.pi);@;)"
;
char *kernel =
#include "mnt/(uname -sr | sed @,s/^/@;/;s/$/@;/@,)"
;
$ cpp -w -P examples.h
char seed[8] = {
0xf9, 0x17, 0x93, 0x83, 0xf6, 0x90, 0xca, 0xa7
};
double pi_squared =
9.86960440109
;
char *kernel =
"Linux 5.16.0-1-amd64"
;
[0] http://github.com/camel-cdr/execfs http://github.com/camel-cdr/execfs
- smegsicle 3y agowhat a great idea this is just what i needed to simplify my build process
- phone8675309 3y agoThis is incredibly cool.
- rramadass 3y agoVery neat and innovative!