Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/basic cmake python linux #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# rez
build

# src files
recipes/*/src/*

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 9 additions & 0 deletions download_linux_srcs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# This utility script may be useful later to act as a host arch triplet guesser
# https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess

# This whole setup should get parameterized later but let's just get started shall we?

curl -O ./reciples/cmake/src/ https://github.com/Kitware/CMake/releases/download/v3.22.3/cmake-3.22.3.tar.gz
curl -O ./recipes/python/src/ https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
curl -O ./recipes/python/src/ https://www.python.org/ftp/python/3.7.12/Python-3.7.12.tgz
1 change: 1 addition & 0 deletions recipes/cmake/3.22.3/build.py
1 change: 1 addition & 0 deletions recipes/cmake/3.22.3/package.py
1 change: 1 addition & 0 deletions recipes/cmake/3.22.3/src
131 changes: 131 additions & 0 deletions recipes/cmake/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#!/usr/bin/env python

import multiprocessing
import os
import re
import shutil
import subprocess
import sys

SOURCE_TAR = "src/cmake-{version}.tar.gz"

CONFIGURE_ENV = {
"linux_x86_64_rocky-8.5": {
"CFLAGS": "-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions "
"-fstack-protector-strong --param=ssp-buffer-size=4 "
"-grecord-gcc-switches -m64 -mtune=generic ",
"LDFLAGS": "-Wl,-z,relro,-rpath={config.package_path}/lib64"
}
}

#CONFIGURE_OPTS = {
# "linux_x86_64_rocky-8.5": #"--build=x86_64-unknown-linux-gnu "
# #"--host-x86_64-unknown-linux-gnu "
# "--prefix={config.package_path} --enable-ipv6 "
# "--enable-shared "
# "--with-dbmliborder=gdbm:ndbm:bdb "
# "--with-system-expat --with-system-ffi "
# # "--enable-optimizations "
# "--without-ensurepip "
#}



def build():

if not build_config.is_installing:
raise SystemExit("ERROR: This build must be run in a mode which would install or release it")

source_tar = os.path.join(build_config.source_path, SOURCE_TAR.format(version=build_config.package_version))

_build_and_install_payload(source_tar)

if build_config.is_releasing:
_lock_payload()

def _build_and_install_payload(source_tar):
cmake_file = os.path.join(build_config.build_path, "CMakeLists.txt")
with open(cmake_file, "w") as outstream:
_generate_cmakelists(source_tar, stream=outstream)

subprocess.check_call(["cmake", "."], cwd=build_config.build_path)
subprocess.check_call(["make"], cwd=build_config.build_path)

def _generate_cmakelists(source_tar, stream=sys.stdout):
"""
Args:
source_tar (str): Path to source tarball
stream (file): Output file stream
"""
qt_gui_enable = "" # possibly hook this up to a qt variant in future
if 'REZ_QT_ROOT' in os.environ:
qt_gui_enable = "--qt-gui"

configure_env = ""
for name, value in CONFIGURE_ENV[build_config.build_variant_str].items():
_str = ' "{var}={value}"'.format(var=name, value=value.format(config=build_config))
configure_env += _str

# configure_opts = CONFIGURE_OPTS[build_config.build_variant_str].format(config=build_config)

stream.write("""
cmake_minimum_required(VERSION 3.0)

project(cmake CXX)

include(ExternalProject)

ExternalProject_Add(
{config.package_name}
URL {source_tarfile}
PREFIX {config.package_name}
SOURCE_DIR build
CONFIGURE_COMMAND env {configure_env} ./bootstrap --prefix={config.package_path} {qt_gui_enable} --parallel={cpus} --system-curl
BUILD_IN_SOURCE 1
BUILD_COMMAND make -j{cpus}
INSTALL_DIR {config.package_path}
)
""".format(
config=build_config,
source_tarfile=source_tar,
configure_env=configure_env,
# configure_opts=configure_opts,
qt_gui_enable=qt_gui_enable,
cpus=multiprocessing.cpu_count(),
)
)

def _lock_payload():
path = os.path.dirname(build_config.package_path)
subprocess.check_call(["/bin/chmod", "-R", "a-w", path])


class BuildConfig(object):
def __init__(self):
self.source_path = os.environ["REZ_BUILD_SOURCE_PATH"]
self.build_path = os.environ["REZ_BUILD_PATH"]
self.package_path = os.environ["REZ_BUILD_INSTALL_PATH"]
self.package_name = os.environ["REZ_BUILD_PROJECT_NAME"]
self.package_version = os.environ["REZ_BUILD_PROJECT_VERSION"]

@property
def is_installing(self):
return os.environ["REZ_BUILD_INSTALL"] == '1'

@property
def is_releasing(self):
return os.environ["REZ_BUILD_TYPE"] in ["central"]

@property
def build_variant_str(self):
desc = "{platform}_{arch}_{os}".format(
platform=os.environ["REZ_PLATFORM_VERSION"],
arch=os.environ["REZ_ARCH_VERSION"],
os=os.environ["REZ_OS_VERSION"],
)
return desc

build_config = BuildConfig()

if __name__ == "__main__":
build()
93 changes: 93 additions & 0 deletions recipes/cmake/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-

name = "cmake"

@early()
def version():
import os
version = os.path.basename(os.getcwd())
return version

@early()
def uuid():
import uuid
return str(uuid.uuid5(uuid.NAMESPACE_DNS, name))

description = \
"""
Open-source and cross-platform family of tools designed to build, test, and package software.
"""

vendor_name = "Kitware"

vendor_type = "external"

opensource = True

source_author = vendor_name

source_license = "BSD 3-clause"

source_type = "c++"

gpl_compatible = True

has_plugins = False

vendor_version = version()

build_type = "python"

package_author = "maxnbk"
build_author = "maxnbk"

relocateable = False

build_requires_source = True
build_requires_internet = False
build_requires_sudo = False

@early()
def tools():
major, minor = version().split('.')[:2]
return [
"2to3",
"idle",
"pydoc",
"python",
"python{major}".format(major=major),
"python{major}.{minor}".format(major=major,minor=minor),
"python{major}.{minor}-config".format(major=major,minor=minor),
"python{major}-config".format(major=major),
"python-config",
"smtpd.py",
]

private_build_requires = [
'gcc-4+',
# 'cmake-3',
# build will rely on the system-level cmake installation because we're being meta for now
# 'python-2.7+<4',
# build will rely on the system-level python interpreter because python package itself will be built using cmake
]

build_command = "python {root}/build.py {install}"

hashed_variants = True

@early()
def variants():
maxnbk marked this conversation as resolved.
Show resolved Hide resolved
from rez.package_py_utils import expand_requires
requires = ["platform-linux", "arch-x86_64", "os-**"]
return [expand_requires(*requires)]

def commands():
env.PATH.prepend("{this.root}/bin")

tests = {
"version_check": 'echo [[ \\"$(cmake --version | head -n 1)\\" -eq \\"cmake version {version}\\" ]]'.format(version=version())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the equivalent of this directly into version() instead, may as well abort early if there's a mismatch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow.

}

with scope('config') as config:
config.release_packages_path = '${SW_EXTERNAL_RELEASE_ROOT}'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have this? User can already provide their own rezconfig.py as per README.md instructions

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should go the way of batteries-included with respect to demonstrating multiple package-repository usage.
Ideally, I'd like to achieve something where specifying "external" / "internal" vendor_type automatically changes the release path.


1 change: 1 addition & 0 deletions recipes/python/2.7.18/build.py
1 change: 1 addition & 0 deletions recipes/python/2.7.18/package.py
1 change: 1 addition & 0 deletions recipes/python/2.7.18/src
1 change: 1 addition & 0 deletions recipes/python/3.7.12/build.py
1 change: 1 addition & 0 deletions recipes/python/3.7.12/package.py
1 change: 1 addition & 0 deletions recipes/python/3.7.12/src
Loading