Move C program to its own file
Problem: Writing C in a heredoc is super janky and I think it's worth avoiding whenever we can. We've also been getting compiler warnings that we should probably resolve. Solution: Move the C to its own file and resolve the compiler warnings.
This commit is contained in:
@ -30,9 +30,10 @@ cd vendor
|
|||||||
TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-$TARGET_ARCH"
|
TARGET="node-v$TARGET_VERSION-$TARGET_PLATFORM-$TARGET_ARCH"
|
||||||
TARBALL="$TARGET.tar.gz"
|
TARBALL="$TARGET.tar.gz"
|
||||||
URL="https://nodejs.org/dist/v$TARGET_VERSION/$TARBALL"
|
URL="https://nodejs.org/dist/v$TARGET_VERSION/$TARBALL"
|
||||||
|
TARGET_NODE="$TARGET/bin/node"
|
||||||
|
|
||||||
wget "$URL"
|
wget "$URL"
|
||||||
tar -xvf "$TARBALL" "$TARGET/bin/node"
|
tar -xvf "$TARBALL" "$TARGET_NODE"
|
||||||
rm -rf "$TARBALL"
|
rm -rf "$TARBALL"
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
@ -43,43 +44,17 @@ rm -rf ./node_modules/sharp
|
|||||||
|
|
||||||
BINARY_NAME="oasis"
|
BINARY_NAME="oasis"
|
||||||
|
|
||||||
echo $BINARY_NAME
|
VENDOR_NODE="vendor/$TARGET_NODE"
|
||||||
|
|
||||||
cat << EOF | gcc -Wall -g -no-pie -o "$BINARY_NAME" -x c -march="$GCC_ARCH" -
|
gcc scripts/oasis.c -Wall -g -no-pie -o "$BINARY_NAME" -march="$GCC_ARCH" -D "NODE=\"$VENDOR_NODE\""
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
|
||||||
static const char node[] = "./vendor/node-v$TARGET_VERSION-$TARGET_PLATFORM-$TARGET_ARCH/bin/node";
|
|
||||||
static const char src[] = "src";
|
|
||||||
|
|
||||||
char** new_argv = malloc(((argc+1) * sizeof *new_argv) + sizeof src);
|
|
||||||
|
|
||||||
int pad = 0;
|
|
||||||
for(int i = 0; i < argc; i++) {
|
|
||||||
size_t length = strlen(argv[i])+1;
|
|
||||||
new_argv[i+pad] = malloc(length);
|
|
||||||
memcpy(new_argv[i+pad], argv[i], length);
|
|
||||||
if (i == 0) {
|
|
||||||
pad = 1;
|
|
||||||
new_argv[i + pad] = src;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
new_argv[argc + 1] = NULL;
|
|
||||||
|
|
||||||
execv(node, new_argv);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
||||||
chmod +x "$BINARY_NAME"
|
chmod +x "$BINARY_NAME"
|
||||||
|
|
||||||
# I think if the zip already exists it's adding files to the existing archive?
|
# I think if the zip already exists it's adding files to the existing archive?
|
||||||
ZIP_PATH="/tmp/oasis-$TARGET_PLATFORM-$TARGET_ARCH.zip"
|
ZIP_PATH="/tmp/oasis-$TARGET_PLATFORM-$TARGET_ARCH.zip"
|
||||||
rm -f "$ZIP_PATH"
|
|
||||||
|
|
||||||
|
rm -f "$ZIP_PATH"
|
||||||
zip -r "$ZIP_PATH" . -x ".git/**"
|
zip -r "$ZIP_PATH" . -x ".git/**"
|
||||||
git clean -fdx
|
|
||||||
|
rm -f oasis
|
||||||
|
rm -rf vendor
|
||||||
|
32
scripts/oasis.c
Normal file
32
scripts/oasis.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#ifndef NODE
|
||||||
|
#define NODE "/usr/bin/node"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
int main (int argc, char *argv[]) {
|
||||||
|
static const char src[] = "src";
|
||||||
|
char** new_argv = malloc(((argc + 1) * sizeof *new_argv) + strlen(src));
|
||||||
|
|
||||||
|
int pad = 0;
|
||||||
|
for(int i = 0; i < argc; i++) {
|
||||||
|
size_t length = strlen(argv[i]) + 1;
|
||||||
|
new_argv[i + pad] = malloc(length);
|
||||||
|
memcpy(new_argv[i + pad], argv[i], length);
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
pad = 1;
|
||||||
|
size_t length = strlen(src) + 1;
|
||||||
|
new_argv[i + pad] = malloc(length);
|
||||||
|
memcpy(new_argv[i + pad], src, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new_argv[argc + 1] = NULL;
|
||||||
|
|
||||||
|
execv(NODE, new_argv);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user