Skip to content

Commit a519f97

Browse files
Init
0 parents  commit a519f97

18 files changed

+2343
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.vscode/
2+
/builddir*
3+
/deps
4+
/dist
5+
*.o

.gitmodules

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[submodule "libfastjson"]
2+
path = libfastjson
3+
url = https://github.com/rsyslog/libfastjson
4+
5+
[submodule "libpatchelf/patchelf"]
6+
path = libpatchelf/patchelf
7+
url = https://github.com/NixOS/patchelf

LICENSE.txt

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
PROD_VER = $(shell cat version.txt)
2+
BUILD_TRIPLET = $(shell uname -m)-redhat-linux
3+
ARCH := $(shell uname -m)
4+
5+
ifeq ($(ARCH), x86_64)
6+
override ARCH = x64
7+
TARGET_TRIPLET = x86_64-linux-gnu
8+
else ifeq ($(ARCH), x64)
9+
TARGET_TRIPLET = x86_64-linux-gnu
10+
else ifeq ($(ARCH), aarch64)
11+
override ARCH = arm64
12+
TARGET_TRIPLET = aarch64-linux-gnu
13+
else ifeq ($(ARCH), arm64)
14+
TARGET_TRIPLET = aarch64-linux-gnu
15+
else ifeq ($(ARCH), arm)
16+
override ARCH = armhf
17+
TARGET_TRIPLET = arm-none-linux-gnueabi
18+
else ifeq ($(ARCH), armhf)
19+
TARGET_TRIPLET = arm-none-linux-gnueabi
20+
endif
21+
22+
SRCDIR = src
23+
DEPSDIR = deps
24+
DISTDIR = dist
25+
BUILDDIR = builddir.$(ARCH)
26+
LIBDIR = $(BUILDDIR)/lib
27+
28+
VSCODE_SERVER = vscode-server
29+
VSCODE_SERVER_TAR = $(DISTDIR)/$(VSCODE_SERVER)_$(PROD_VER)_$(ARCH).tar.gz
30+
VSCODE_SERVER_DIR = $(BUILDDIR)/$(VSCODE_SERVER)
31+
32+
SRV_TAR = $(DEPSDIR)/vscode-srv-$(ARCH).tar.gz
33+
CLI_TAR = $(DEPSDIR)/vscode-cli-$(ARCH).tar.gz
34+
35+
TOOLCHAIN_DEPS = $(DEPSDIR)/linux-src.tar.xz $(DEPSDIR)/binutils-src.tar.xz $(DEPSDIR)/glibc-src.tar.xz $(DEPSDIR)/gcc-src.tar.xz $(DEPSDIR)/gmp-src.tar.xz $(DEPSDIR)/mpfr-src.tar.xz $(DEPSDIR)/mpc-src.tar.gz
36+
VSCODE_DEPS = $(SRV_TAR) $(CLI_TAR)
37+
38+
LIBFASTJSON = $(LIBDIR)/libfastjson.a
39+
LIBPATCHELF = $(LIBDIR)/libpatchelf.a
40+
41+
HEADERS = $(wildcard libfastjson/*.h) $(wildcard libfastjson/*.h)
42+
CODEBIN = $(BUILDDIR)/code
43+
CODESRC = $(SRCDIR)/code.c
44+
45+
TOOLCHAIN_DIR = $(BUILDDIR)/toolchain
46+
CROSS_PREFIX = $(TOOLCHAIN_DIR)/bin/$(TARGET_TRIPLET)-
47+
CROSS_CC = $(CROSS_PREFIX)gcc
48+
CROSS_CXX = $(CROSS_PREFIX)g++
49+
CROSS_STRIP = $(TOOLCHAIN_DIR)/$(TARGET_TRIPLET)/bin/strip
50+
CROSS_LIBDIR = $(TOOLCHAIN_DIR)/$(TARGET_TRIPLET)/lib
51+
CROSS_LIB64DIR = $(TOOLCHAIN_DIR)/$(TARGET_TRIPLET)/lib64
52+
TOOLCHAIN = $(CROSS_CC) $(CROSS_CXX) $(CROSS_STRIP)
53+
54+
INCLUDES = -I.
55+
CFLAGS += -static -Wall -Wextra $(INCLUDES)
56+
LDFLAGS += -lstdc++ -lm
57+
58+
all: $(VSCODE_SERVER_TAR)
59+
60+
code: $(CODEBIN)
61+
62+
toolchain: $(TOOLCHAIN)
63+
64+
$(VSCODE_DEPS) $(TOOLCHAIN_DEPS):
65+
env TARGET_TRIPLET='$(TARGET_TRIPLET)' bash scripts/download-deps.sh
66+
67+
$(CROSS_CC) $(CROSS_CXX) $(CROSS_STRIP): $(TOOLCHAIN_DEPS)
68+
env BUILD_TRIPLET='$(BUILD_TRIPLET)' TARGET_TRIPLET='$(TARGET_TRIPLET)' BUILDDIR='$(shell realpath $(BUILDDIR))' bash scripts/build-gcc-toolchain.sh
69+
70+
$(LIBFASTJSON): $(TOOLCHAIN)
71+
cd libfastjson && ./autogen.sh CC='$(shell realpath $(CROSS_CC))' --prefix='$(shell realpath $(BUILDDIR))' --build='$(BUILD_TRIPLET)' --host='$(TARGET_TRIPLET)' && $(MAKE) clean && $(MAKE) install
72+
73+
$(LIBPATCHELF): $(TOOLCHAIN)
74+
cd libpatchelf && $(MAKE) clean && $(MAKE) LIBDIR='$(shell realpath $(LIBDIR))' CROSS_PREFIX='$(shell realpath $(CROSS_PREFIX))'
75+
76+
$(CODEBIN): $(TOOLCHAIN) $(CODESRC) $(HEADERS) $(LIBFASTJSON) $(LIBPATCHELF)
77+
$(CROSS_CC) $(CFLAGS) -o $(CODEBIN) $(CODESRC) $(LIBFASTJSON) $(LIBPATCHELF) $(LDFLAGS)
78+
$(CROSS_STRIP) --strip-all -R .comment $(CODEBIN)
79+
80+
$(VSCODE_SERVER_TAR): $(VSCODE_DEPS) $(TOOLCHAIN) $(CLI_TAR) $(SRV_TAR) $(CODEBIN)
81+
rm -rf $(VSCODE_SERVER_DIR) $(BUILDDIR)/cli $(BUILDDIR)/srv
82+
mkdir $(VSCODE_SERVER_DIR) $(BUILDDIR)/cli $(BUILDDIR)/srv
83+
tar xf $(CLI_TAR) -C $(BUILDDIR)/cli code
84+
cp -a $(BUILDDIR)/cli/code "$(VSCODE_SERVER_DIR)/code-$$(cat $(DEPSDIR)/vscode-version.txt)-cli"
85+
cp -a $(CODEBIN) "$(VSCODE_SERVER_DIR)/code-$$(cat $(DEPSDIR)/vscode-version.txt)"
86+
ln -s "code-$$(cat $(DEPSDIR)/vscode-version.txt)" $(VSCODE_SERVER_DIR)/code-latest
87+
tar xf $(SRV_TAR) -C $(BUILDDIR)/srv --strip-components=1
88+
mkdir -p "$(VSCODE_SERVER_DIR)/cli/servers/Stable-$$(cat $(DEPSDIR)/vscode-version.txt)"
89+
cp -a $(BUILDDIR)/srv "$(VSCODE_SERVER_DIR)/cli/servers/Stable-$$(cat $(DEPSDIR)/vscode-version.txt)/server"
90+
mkdir -p $(VSCODE_SERVER_DIR)/gnu
91+
if [ -e '$(CROSS_LIB64DIR)' ]; then cp -a '$(CROSS_LIB64DIR)'/. $(VSCODE_SERVER_DIR)/gnu; fi
92+
cp -a '$(CROSS_LIBDIR)'/. $(VSCODE_SERVER_DIR)/gnu
93+
find $(VSCODE_SERVER_DIR)/gnu -regex '.*\.\(a\|la\|o\|py\|spec\)' -delete
94+
mkdir -p $(DISTDIR)
95+
cd $(BUILDDIR) && tar --owner=0 --group=0 --no-same-owner --no-same-permissions -czf ../$(VSCODE_SERVER_TAR) $(VSCODE_SERVER)
96+
97+
clean_libfastjson:
98+
cd libfastjson && test -f Makefile && $(MAKE) distclean || true
99+
cd libfastjson && rm -rf .deps INSTALL Makefile.in aclocal.m4 autom4te.cache compile config.guess config.h.in config.sub configure depcomp install-sh ltmain.sh m4/libtool.m4 m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 missing test-driver tests/.deps tests/Makefile.in
100+
101+
clean_libpatchelf:
102+
cd libpatchelf && $(MAKE) clean || true
103+
104+
clean: clean_libfastjson clean_libpatchelf
105+
$(RM) -r $(BUILDDIR) $(DISTDIR)
106+
107+
clean_deps:
108+
$(RM) -r $(BUILDDIR) $(DEPSDIR)
109+
110+
clean_all: clean clean_deps
111+
112+
.PHONY: all code clean clean_libfastjson clean_libpatchelf

README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# vscode-server-centos7
2+
3+
A specially patched VS Code Server that runs on RHEL/CentOS 7.
4+
5+
## Quick Start
6+
7+
1. Download a tarball from the [Releases](https://github.com/MikeWang000000/vscode-server-centos7/releases) page to your server.
8+
9+
2. Execute the following commands on your server:
10+
11+
```bash
12+
mkdir -p ~/.vscode-server
13+
tar xzf vscode-server_*.tar.gz -C ~/.vscode-server --strip-components 1
14+
~/.vscode-server/code-latest --patch-now
15+
```
16+
17+
3. Enjoy!
18+
19+
20+
## Build from Source
21+
22+
1. Install YUM dependencies:
23+
24+
```bash
25+
sudo scripts/yum-install.sh
26+
```
27+
28+
2. Download additional dependencies:
29+
30+
```bash
31+
scripts/download-deps.sh
32+
```
33+
34+
3. Start the build process:
35+
36+
```bash
37+
make
38+
```
39+
40+
You can specify the value of `ARCH` to build for different architectures:
41+
42+
```bash
43+
make ARCH=x64
44+
```
45+
46+
```bash
47+
make ARCH=arm64
48+
```
49+
50+
```bash
51+
make ARCH=armhf
52+
```
53+
54+
A full build process may take a long time since it involves compiling the glibc and GCC toolchains.
55+
56+
57+
## License
58+
59+
**Licenses for this repository:**
60+
[GNU General Public License v3.0](./LICENSE.txt)
61+
62+
Microsoft Visual Studio Code product license:
63+
https://code.visualstudio.com/license
64+
65+
Visual Studio Code - Open Source:
66+
https://github.com/microsoft/vscode/blob/main/LICENSE.txt
67+
68+
libfastjson:
69+
https://github.com/rsyslog/libfastjson/blob/master/COPYING
70+
71+
PatchELF:
72+
https://github.com/NixOS/patchelf/blob/master/COPYING
73+
74+
The GNU C Library:
75+
https://www.gnu.org/software/libc/manual/html_node/Copying.html
76+
77+
The GNU C++ Library:
78+
https://gcc.gnu.org/onlinedocs/libstdc++/manual/license.html

libfastjson

Submodule libfastjson added at a4c8897

libpatchelf/Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
CROSS_PREFIX ?=
2+
CXX = $(CROSS_PREFIX)g++
3+
AR = $(CROSS_PREFIX)gcc-ar
4+
5+
CFLAGS += -std=c++17 -Wall -Wextra
6+
7+
LIBDIR ?= lib
8+
9+
HEADERS = $(wildcard *.h)
10+
SRC = libpatchelf.cc
11+
OBJ = libpatchelf.o
12+
LIB = $(LIBDIR)/libpatchelf.a
13+
14+
all: $(LIB)
15+
16+
$(OBJ): $(SRC) $(HEADERS)
17+
$(CXX) -c $(CFLAGS) -o $(OBJ) $(SRC)
18+
19+
$(LIB): $(OBJ)
20+
mkdir -p $(LIBDIR)
21+
$(AR) rcs $(LIB) $(OBJ)
22+
23+
clean:
24+
$(RM) -r $(OBJ) $(LIBDIR)
25+
26+
.PHONY: all clean

libpatchelf/libpatchelf.cc

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#define main(ARGC, ARGV) patchelf_main(ARGC, ARGV)
2+
#define _FILE_OFFSET_BITS 64
3+
#include "libpatchelf.h"
4+
#include "patchelf/src/patchelf.cc"
5+
6+
int patchelf_get_interpreter(const char *filename, char *interpreter,
7+
size_t n, int print_err)
8+
{
9+
try {
10+
auto fileContents = readFile(filename);
11+
std::string interp;
12+
13+
if (getElfType(fileContents).is32Bit) {
14+
ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off,
15+
Elf32_Dyn, Elf32_Sym, Elf32_Versym, Elf32_Verdef,
16+
Elf32_Verdaux, Elf32_Verneed, Elf32_Vernaux, Elf32_Rel,
17+
Elf32_Rela, 32> elfFile(fileContents);
18+
interp = elfFile.getInterpreter();
19+
} else {
20+
ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off,
21+
Elf64_Dyn, Elf64_Sym, Elf64_Versym, Elf64_Verdef,
22+
Elf64_Verdaux, Elf64_Verneed, Elf64_Vernaux, Elf64_Rel,
23+
Elf64_Rela, 64> elfFile(fileContents);
24+
interp = elfFile.getInterpreter();
25+
}
26+
if (interp.size() >= n)
27+
error("interpreter string too long");
28+
strncpy(interpreter, interp.c_str(), n);
29+
} catch (std::exception & e) {
30+
if (print_err) {
31+
fprintf(stderr, "patchelf: %s\n", e.what());
32+
}
33+
return -1;
34+
}
35+
return 0;
36+
}
37+
38+
int patchelf_set_interpreter(const char *filename, const char *filename_new,
39+
const char *interpreter, int print_err)
40+
{
41+
try {
42+
auto fileContents = readFile(filename);
43+
std::string newInterpreter(interpreter);
44+
45+
if (getElfType(fileContents).is32Bit) {
46+
ElfFile<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Addr, Elf32_Off,
47+
Elf32_Dyn, Elf32_Sym, Elf32_Versym, Elf32_Verdef,
48+
Elf32_Verdaux, Elf32_Verneed, Elf32_Vernaux, Elf32_Rel,
49+
Elf32_Rela, 32> elfFile(fileContents);
50+
elfFile.setInterpreter(newInterpreter);
51+
writeFile(filename_new, elfFile.fileContents);
52+
} else {
53+
ElfFile<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Addr, Elf64_Off,
54+
Elf64_Dyn, Elf64_Sym, Elf64_Versym, Elf64_Verdef,
55+
Elf64_Verdaux, Elf64_Verneed, Elf64_Vernaux, Elf64_Rel,
56+
Elf64_Rela, 64> elfFile(fileContents);
57+
elfFile.setInterpreter(newInterpreter);
58+
writeFile(filename_new, elfFile.fileContents);
59+
}
60+
} catch (std::exception & e) {
61+
if (print_err) {
62+
fprintf(stderr, "patchelf: %s\n", e.what());
63+
}
64+
return -1;
65+
}
66+
return 0;
67+
}

libpatchelf/libpatchelf.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef LIBPATCHELF_H
2+
#define LIBPATCHELF_H
3+
4+
#include <stddef.h>
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
int patchelf_get_interpreter(const char *filename, char *interpreter,
9+
size_t n, int print_err);
10+
11+
int patchelf_set_interpreter(const char *filename, const char *filename_new,
12+
const char *interpreter, int print_err);
13+
#ifdef __cplusplus
14+
}
15+
#endif
16+
17+
#endif /* LIBPATCHELF_H */

libpatchelf/patchelf

Submodule patchelf added at 523f401

0 commit comments

Comments
 (0)