bare-build 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CMakeLists.txt +27 -15
  2. package/README.md +2 -0
  3. package/bin.js +3 -0
  4. package/index.js +5 -5
  5. package/lib/assets/apple/icon.png +0 -0
  6. package/lib/assets/linux/icon.png +0 -0
  7. package/lib/assets/windows/icon.png +0 -0
  8. package/lib/assets.js +13 -0
  9. package/lib/builtins.json +7 -0
  10. package/lib/fs.js +2 -2
  11. package/lib/platform/apple/create-app.js +6 -8
  12. package/lib/platform/apple/create-executable.js +60 -0
  13. package/lib/platform/apple/create-package-component.js +2 -2
  14. package/lib/platform/apple/create-package.js +2 -2
  15. package/lib/platform/apple/sign.js +58 -9
  16. package/lib/platform/apple.js +24 -11
  17. package/lib/platform/linux/create-app-dir.js +2 -1
  18. package/lib/platform/linux/create-app-image.js +1 -1
  19. package/lib/platform/linux/create-executable.js +50 -0
  20. package/lib/platform/linux.js +24 -11
  21. package/lib/platform/windows/create-executable.js +50 -0
  22. package/lib/platform/windows/create-msix-content-directory.js +11 -5
  23. package/lib/platform/windows/create-msix.js +1 -1
  24. package/lib/platform/windows.js +24 -11
  25. package/lib/runtime/apple.h +22 -0
  26. package/lib/runtime/linux.h +17 -0
  27. package/lib/runtime/windows.h +45 -0
  28. package/lib/runtime.bundle.h +16696 -0
  29. package/lib/runtime.bundle.h.d +1 -0
  30. package/lib/runtime.c +81 -33
  31. package/lib/runtime.js +36 -0
  32. package/package.json +6 -3
  33. package/prebuilds/darwin-arm64/bare +0 -0
  34. package/prebuilds/darwin-x64/bare +0 -0
  35. package/prebuilds/ios-arm64/bare +0 -0
  36. package/prebuilds/ios-arm64-simulator/bare +0 -0
  37. package/prebuilds/ios-x64-simulator/bare +0 -0
  38. package/prebuilds/linux-arm64/bare +0 -0
  39. package/prebuilds/linux-x64/bare +0 -0
  40. package/prebuilds/win32-arm64/bare.exe +0 -0
  41. package/prebuilds/win32-x64/bare.exe +0 -0
@@ -1,7 +1,9 @@
1
1
  const path = require('path')
2
2
  const link = require('bare-link')
3
3
  const unpack = require('bare-unpack')
4
+ const { PE } = require('bare-lief')
4
5
  const fs = require('../../fs')
6
+ const { windows } = require('../../assets')
5
7
  const prebuilds = require('../../prebuilds')
6
8
  const sign = require('./sign')
7
9
 
@@ -13,7 +15,7 @@ module.exports = async function* createMSIXContentDirectory(
13
15
  out,
14
16
  opts = {}
15
17
  ) {
16
- const { name = pkg.name, icon } = opts
18
+ const { name = pkg.name || 'App', icon = windows.icon } = opts
17
19
 
18
20
  const app = path.resolve(out, name)
19
21
 
@@ -30,8 +32,12 @@ module.exports = async function* createMSIXContentDirectory(
30
32
 
31
33
  yield* link(base, { ...opts, hosts: [host], out: bin })
32
34
 
35
+ const binary = new PE.Binary(await fs.readFile(prebuilds[host]()))
36
+
37
+ binary.optionalHeader.subsystem = PE.OptionalHeader.SUBSYSTEM.WINDOWS_GUI
38
+
33
39
  const executable = path.join(bin, name + '.exe')
34
- await fs.copyFile(prebuilds[host](), executable)
40
+ binary.toDisk(executable)
35
41
  await sign(executable, opts)
36
42
  yield executable
37
43
 
@@ -70,13 +76,13 @@ const unsignedSubject = 'CN=AppModelSamples, OID.2.25.31172936891398431765440773
70
76
 
71
77
  function createAppxManifest(pkg, host, opts = {}) {
72
78
  let {
73
- name = pkg.name,
79
+ name = pkg.name || 'App',
74
80
  identifier = toIdentifier(name),
75
- version = pkg.version,
81
+ version = pkg.version || '1.0.0',
76
82
  description = pkg.description,
77
83
  author = pkg.author,
78
84
  language = 'en-US',
79
- icon,
85
+ icon = windows.icon,
80
86
  subject = unsignedSubject
81
87
  } = opts
82
88
 
@@ -4,7 +4,7 @@ const run = require('../../run')
4
4
  const sign = require('./sign')
5
5
 
6
6
  module.exports = async function* createMSIX(pkg, contentDirectory, out, opts = {}) {
7
- const { name = pkg.name } = opts
7
+ const { name = pkg.name || 'App' } = opts
8
8
 
9
9
  const msix = path.resolve(out, name + '.msix')
10
10
  await fs.rm(msix)
@@ -2,9 +2,10 @@ const path = require('path')
2
2
  const fs = require('../fs')
3
3
  const createMSIX = require('./windows/create-msix')
4
4
  const createMSIXContentDirectory = require('./windows/create-msix-content-directory')
5
+ const createExecutable = require('./windows/create-executable')
5
6
 
6
7
  module.exports = async function* windows(base, pkg, bundle, opts = {}) {
7
- const { hosts = [], package = false, out = '.' } = opts
8
+ const { hosts = [], standalone = false, package = false, out = '.' } = opts
8
9
 
9
10
  const archs = new Map()
10
11
 
@@ -39,16 +40,28 @@ module.exports = async function* windows(base, pkg, bundle, opts = {}) {
39
40
 
40
41
  contentDirectory = yield* createMSIXContentDirectory(base, pkg, bundle, host, out, opts)
41
42
  } else {
42
- contentDirectory = yield* createMSIXContentDirectory(
43
- base,
44
- pkg,
45
- bundle,
46
- host,
47
- archs.size === 1 ? path.resolve(out) : path.resolve(out, arch),
48
- opts
49
- )
50
-
51
- result.push(contentDirectory)
43
+ if (standalone) {
44
+ result.push(
45
+ yield* createExecutable(
46
+ pkg,
47
+ bundle,
48
+ host,
49
+ archs.size === 1 ? path.resolve(out) : path.resolve(out, arch),
50
+ opts
51
+ )
52
+ )
53
+ } else {
54
+ result.push(
55
+ yield* createMSIXContentDirectory(
56
+ base,
57
+ pkg,
58
+ bundle,
59
+ host,
60
+ archs.size === 1 ? path.resolve(out) : path.resolve(out, arch),
61
+ opts
62
+ )
63
+ )
64
+ }
52
65
 
53
66
  continue
54
67
  }
@@ -0,0 +1,22 @@
1
+ #include <mach-o/getsect.h>
2
+ #include <mach-o/loader.h>
3
+ #include <stddef.h>
4
+ #include <stdint.h>
5
+ #include <uv.h>
6
+
7
+ extern const struct mach_header_64 _mh_execute_header;
8
+
9
+ static inline void
10
+ bare__prepare_main(void) {}
11
+
12
+ static inline int
13
+ bare__get_embedded_bundle(uv_buf_t *result) {
14
+ size_t len;
15
+ uint8_t *bundle = getsectiondata(&_mh_execute_header, "__BARE", "__bundle", &len);
16
+
17
+ if (bundle == NULL) return -1;
18
+
19
+ *result = uv_buf_init((char *) bundle, len);
20
+
21
+ return 0;
22
+ }
@@ -0,0 +1,17 @@
1
+ #include <stddef.h>
2
+ #include <uv.h>
3
+
4
+ extern char __bare_bundle_begin[] __attribute__((weak));
5
+ extern char __bare_bundle_end[] __attribute__((weak));
6
+
7
+ static inline void
8
+ bare__prepare_main(void) {}
9
+
10
+ static inline int
11
+ bare__get_embedded_bundle(uv_buf_t *result) {
12
+ if (__bare_bundle_begin == NULL || __bare_bundle_end == NULL) return -1;
13
+
14
+ *result = uv_buf_init(__bare_bundle_begin, __bare_bundle_end - __bare_bundle_begin);
15
+
16
+ return 0;
17
+ }
@@ -0,0 +1,45 @@
1
+ #include <string.h>
2
+ #include <uv.h>
3
+ #include <windows.h>
4
+
5
+ static inline void
6
+ bare__prepare_main(void) {
7
+ if (GetConsoleWindow() == NULL) {
8
+ freopen("NUL", "r", stdin);
9
+ freopen("NUL", "w", stdout);
10
+ freopen("NUL", "w", stderr);
11
+ }
12
+ }
13
+
14
+ static inline int
15
+ bare__get_embedded_bundle(uv_buf_t *result) {
16
+ HMODULE module = GetModuleHandle(NULL);
17
+
18
+ PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER) module;
19
+ if (dos->e_magic != IMAGE_DOS_SIGNATURE) {
20
+ return -1;
21
+ }
22
+
23
+ PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS) ((BYTE *) module + dos->e_lfanew);
24
+ if (nt->Signature != IMAGE_NT_SIGNATURE) {
25
+ return -1;
26
+ }
27
+
28
+ PIMAGE_SECTION_HEADER sections = IMAGE_FIRST_SECTION(nt);
29
+
30
+ for (int i = 0, n = nt->FileHeader.NumberOfSections; i < n; i++) {
31
+ PIMAGE_SECTION_HEADER section = &sections[i];
32
+
33
+ char name[9];
34
+ name[8] = '\0';
35
+ memcpy(name, section->Name, 8);
36
+
37
+ if (strcmp(name, ".bare") == 0) {
38
+ *result = uv_buf_init((char *) ((BYTE *) module + section->VirtualAddress), sections->Misc.VirtualSize);
39
+
40
+ return 0;
41
+ }
42
+ }
43
+
44
+ return -1;
45
+ }