Made build work partially outside windows.

This commit is contained in:
Brad Nelson
2024-01-02 21:24:51 -08:00
parent c9742cebf8
commit 21cf660212
8 changed files with 156 additions and 66 deletions

7
BUILD
View File

@ -18,10 +18,3 @@ Include('web')
Include('pico-ice')
Include('esp32')
Include('site')
Default('windows')
Default('posix')
Default('web')
Default('esp32')
Default('pico')
Default('site')

View File

@ -26,6 +26,14 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
ROOT_DIR = SCRIPT_DIR
NINJA_BUILD = os.path.join(ROOT_DIR, 'build.ninja')
SRC_DIR = os.path.relpath(ROOT_DIR, os.getcwd())
if SRC_DIR == '.':
DST_DIR = 'out'
NINJA_DIR = '.'
else:
DST_DIR = '.'
NINJA_DIR = '.'
CFLAGS_COMMON = [
'-O2',
'-I', '$src',
@ -105,42 +113,85 @@ WIN_LFLAGS64 = [
'/LIBPATH:"c:/Program Files (x86)/Windows Kits/10/Lib/10.0.19041.0/ucrt/x64"',
] + WIN_LIBS
LOCALAPPDATAR = str(subprocess.check_output('cmd.exe /c echo "%LOCALAPPDATA%"',
shell=True, stderr=subprocess.DEVNULL).splitlines()[0], 'ascii').replace('\\', '/')
LOCALAPPDATA = LOCALAPPDATAR.replace('C:/', '/mnt/c/')
ARDUINO_CLI = LOCALAPPDATA + '/Programs/arduino-ide/resources/app/lib/backend/resources/arduino-cli.exe'
WINTMP = LOCALAPPDATA + '/Temp'
WINTMPR = LOCALAPPDATAR + '/Temp'
PICO_ICE_ENABLED = False
WINDOWS_ENABLED = False
WINTMP = '/UNSUPPORTED'
ARDUINO_CLI = 'UNSUPPORTED'
WIN_CL32 = 'UNSUPPORTED'
WIN_CL64 = 'UNSUPPORTED'
WIN_LINK32 = 'UNSUPPORTED'
WIN_LINK64 = 'UNSUPPORTED'
WIN_RC32 = 'UNSUPPORTED'
WIN_RC64 = 'UNSUPPORTED'
# Mutable global state.
build_files = []
output = ''
def Escape(path):
return path.replace(' ', '\\ ').replace('(', '\\(').replace(')', '\\)')
def LSQ(path):
return '"' + str(subprocess.check_output('ls ' + Escape(path), shell=True), 'ascii').splitlines()[0] + '"'
return '"' + str(subprocess.check_output('ls ' + Escape(path), shell=True,
stderr=subprocess.DEVNULL), 'ascii').splitlines()[0] + '"'
PROGFILES = '/mnt/c/Program Files (x86)'
MSVS = PROGFILES + '/Microsoft Visual Studio'
MSKITS = PROGFILES + '/Windows Kits'
WIN_CL32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/cl.exe')
WIN_CL64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/cl.exe')
WIN_LINK32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/link.exe')
WIN_LINK64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/link.exe')
WIN_RC32 = LSQ(MSKITS + '/*/bin/*/x86/rc.exe')
WIN_RC64 = LSQ(MSKITS + '/*/bin/*/x64/rc.exe')
def DetectWindowsTools(args):
global WINDOWS_ENABLED
global WINTMP, ARDUINO_CLI
global WIN_CL32, WIN_CL64, WIN_LINK32, WIN_LINK64, WIN_RC32, WIN_RC64
try:
LOCALAPPDATAR = str(subprocess.check_output('cmd.exe /c echo "%LOCALAPPDATA%"', shell=True,
stderr=subprocess.DEVNULL).splitlines()[0], 'ascii').replace('\\', '/')
except:
if not args.quiet:
sys.stderr.write('Windows %LOCALAPPDATA% not available, Windows support disabled.\n')
return
LOCALAPPDATA = LOCALAPPDATAR.replace('C:/', '/mnt/c/')
ARDUINO_CLI = LOCALAPPDATA + '/Programs/arduino-ide/resources/app/lib/backend/resources/arduino-cli.exe'
WINTMP = LOCALAPPDATA + '/Temp'
WINTMPR = LOCALAPPDATAR + '/Temp'
PROGFILES = '/mnt/c/Program Files (x86)'
MSVS = PROGFILES + '/Microsoft Visual Studio'
MSKITS = PROGFILES + '/Windows Kits'
try:
WIN_CL32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/cl.exe')
WIN_CL64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/cl.exe')
WIN_LINK32 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x86/link.exe')
WIN_LINK64 = LSQ(MSVS + '/*/*/VC/Tools/MSVC/*/bin/Hostx86/x64/link.exe')
WIN_RC32 = LSQ(MSKITS + '/*/bin/*/x86/rc.exe')
WIN_RC64 = LSQ(MSKITS + '/*/bin/*/x64/rc.exe')
except:
if not args.quiet:
sys.stderr.write('Windows tools not available, Windows support disabled.\n')
return
WINDOWS_ENABLED = True
D8 = LSQ('${HOME}/src/v8/v8/out/x64.release/d8')
NODEJS = LSQ('/usr/bin/nodejs')
SRC_DIR = os.path.relpath(ROOT_DIR, os.getcwd())
if SRC_DIR == '.':
DST_DIR = 'out'
NINJA_DIR = '.'
else:
DST_DIR = '.'
NINJA_DIR = '.'
def DetectGenericTools(args):
global D8, NODEJS, PICO_ICE_ENABLED
try:
D8 = LSQ('${HOME}/src/v8/v8/out/x64.release/d8')
except:
if not args.quiet:
sys.stderr.write('V8 checkout in $HOME/src/v8 not found, ignoring.\n')
try:
NODEJS = LSQ('/usr/bin/nodejs')
except:
if not args.quiet:
sys.stderr.write('/usr/bin/nodejs not found, required!\n')
sys.exit(1)
try:
LSQ('/usr/bin/arm-none-eabi-gcc')
PICO_ICE_ENABLED = True
except:
if not args.quiet:
sys.stderr.write('Missing package gcc-arm-none-eabi, pico-ice diabled!\n')
build_files = []
output = f"""
def InitOutput():
global output
output = f"""
ninja_required_version = 1.1
src = {SRC_DIR}
dst = {DST_DIR}
@ -456,11 +507,22 @@ def Default(target):
return target
class SkipFileException(Exception):
pass
def Return():
raise SkipFileException()
def Include(path):
build_files.append(os.path.join('$src', path, 'BUILD'))
path = os.path.join(ROOT_DIR, path, 'BUILD')
data = open(path).read()
exec(data)
try:
exec(data)
except SkipFileException:
pass
def Main():
@ -469,6 +531,9 @@ def Main():
description='Generate ninja.build')
parser.add_argument('-q', '--quiet', action='store_true')
args = parser.parse_args()
DetectGenericTools(args)
DetectWindowsTools(args)
InitOutput()
Include('.')
with open('build.ninja', 'w') as fh:
fh.write(output)

View File

@ -66,6 +66,7 @@ Run('$dst/gen/esp32_sim_opcodes.h', '$dst/gen/print-esp32-builtins')
# Main Alias.
Alias('esp32', ' '.join(ESP32_FILES))
Default('esp32')
# Automate building / flashing.
BOARDS = {

View File

@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
if not PICO_ICE_ENABLED:
Return()
PICO_ICE_FILES = []
PICO_ICE_ZIP_FILES = []
@ -42,12 +45,18 @@ Command(' '.join(['$dst/pico-ice/build.ninja',
'cmake $dst/pico-ice -G Ninja -S pico-ice -B $dst/pico-ice 2>&1 | cat >$dst/pico-ice/cmake.err')
# Check out submodules if needed.
Command('$src/pico-ice/pico-sdk/README.md',
Command(' '.join([
'$src/pico-ice/pico-sdk/README.md',
'$src/pico-ice/pico-sdk/LICENSE.TXT',
]),
'', 'git submodule update --init pico-ice/pico-sdk')
Command('$src/pico-ice/pico-sdk/lib/tinyusb/README.rst',
'$src/pico-ice/pico-sdk/README.md',
'cd $src/pico-ice/pico-sdk && git submodule update --init lib/tinyusb')
Command('pico-ice/pico-ice-sdk/README.md',
Command(' '.join([
'$src/pico-ice/pico-ice-sdk/README.md',
'$src/pico-ice/pico-ice-sdk/LICENSE.md',
]),
'', 'git submodule update --init pico-ice/pico-ice-sdk')
# Zip it.
@ -65,3 +74,4 @@ Importation('$dst/gen/pico_ice_boot.h', '$src/pico-ice/pico_ice_boot.fs', name='
# Main Alias.
Alias('pico', ' '.join(PICO_ICE_FILES))
Default('pico')

View File

@ -25,3 +25,5 @@ OneShot('install',
'$dst/posix/ueforth',
'sudo cp $dst/posix/ueforth /usr/bin/ueforth',
pool='console')
Default('posix')

View File

@ -48,11 +48,15 @@ DEPLOY_ITEMS += [
'esp-cam-wiring.jpg',
'serial_bridge.jpg',
]
] + [
Copy('$dst/deploy/static/favicon.ico', '$dst/resources/eforth.ico'),
]
if WINDOWS_ENABLED:
DEPLOY_ITEM += [
Copy('$dst/deploy/static/favicon.ico', '$dst/resources/eforth.ico'),
]
Alias('site', ' '.join(DEPLOY_ITEMS))
Default('site')
Alias('deploy', ' '.join([
Command('deploy-esp32', 'site',
@ -61,7 +65,9 @@ Alias('deploy', ' '.join([
'cd $dst/deploy && gcloud app deploy -q --project eforth *.yaml', pool='console'),
]))
PUBLISH_PARTS = [
PUBLISH_PARTS = []
PUBLISH_PARTS += [
Alias('publish-esp32', ' '.join([
Publish('publish-esp32-rev',
'$dst/esp32/ESP32forth.zip',
@ -70,14 +76,6 @@ PUBLISH_PARTS = [
'$dst/esp32/ESP32forth.zip',
'ESP32forth-{{VERSION}}.zip'),
])),
Alias('publish-pico-ice', ' '.join([
Publish('publish-pico-ice-rev',
'$dst/pico-ice/ueforth-pico-ice.zip',
'ueforth-pico-ice-{{VERSION}}-{{REVSHORT}}.zip'),
Publish('publish-pico-ice-ver',
'$dst/pico-ice/ueforth-pico-ice.zip',
'ueforth-pico-ice-{{VERSION}}.zip'),
])),
Alias('publish-linux', ' '.join([
Publish('publish-linux-rev',
'$dst/posix/ueforth',
@ -94,26 +92,42 @@ PUBLISH_PARTS = [
'$dst/web/ueforth.js',
'ueforth-{{VERSION}}.js'),
])),
Alias('publish-win', ' '.join([
Alias('publish-win32', ' '.join([
Publish('publish-win32-rev',
'$dst/windows/uEf32.exe',
'uEf32-{{VERSION}}-{{REVSHORT}}.exe'),
Publish('publish-win32-ver',
'$dst/windows/uEf32.exe',
'uEf32-{{VERSION}}.exe'),
])),
Alias('publish-win64', ' '.join([
Publish('publish-win64-rev',
'$dst/windows/uEf64.exe',
'uEf64-{{VERSION}}-{{REVSHORT}}.exe'),
Publish('publish-win64-ver',
'$dst/windows/uEf64.exe',
'uEf64-{{VERSION}}.exe'),
])),
])),
]
if PICO_ICE_ENABLED:
PUBLISH_PARTS += [
Alias('publish-pico-ice', ' '.join([
Publish('publish-pico-ice-rev',
'$dst/pico-ice/ueforth-pico-ice.zip',
'ueforth-pico-ice-{{VERSION}}-{{REVSHORT}}.zip'),
Publish('publish-pico-ice-ver',
'$dst/pico-ice/ueforth-pico-ice.zip',
'ueforth-pico-ice-{{VERSION}}.zip'),
])),
]
if WINDOWS_ENABLED:
PUBLISH_PARTS += [
Alias('publish-win', ' '.join([
Alias('publish-win32', ' '.join([
Publish('publish-win32-rev',
'$dst/windows/uEf32.exe',
'uEf32-{{VERSION}}-{{REVSHORT}}.exe'),
Publish('publish-win32-ver',
'$dst/windows/uEf32.exe',
'uEf32-{{VERSION}}.exe'),
])),
Alias('publish-win64', ' '.join([
Publish('publish-win64-rev',
'$dst/windows/uEf64.exe',
'uEf64-{{VERSION}}-{{REVSHORT}}.exe'),
Publish('publish-win64-ver',
'$dst/windows/uEf64.exe',
'uEf64-{{VERSION}}.exe'),
])),
])),
]
Alias('publish', ' '.join([
Command('publish-index', ' '.join([
'$src/tools/webindex.py',

View File

@ -34,3 +34,4 @@ WEB_ITEMS = [
]
Alias('web', ' '.join(WEB_ITEMS))
Default('web')

View File

@ -12,7 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
if not WINDOWS_ENABLED:
Return()
Alias('windows', 'win32 win64')
Default('windows')
# Create boot.
Importation('$dst/gen/windows_boot.h', '$src/windows/windows_boot.fs',