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

Add a Swift Package Manager package #3308

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ Thumbs.db
# Ignore python compiled files
*.pyc
/test/android/jni/#Android.mk#

# Swift package manager
/.swiftpm
/.build
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ check_include_files(malloc.h HAVE_MALLOC_H)
configure_file(src/realm/util/config.h.in src/realm/util/config.h)

# Configure source code to use right version number
configure_file(src/realm/version.hpp.in src/realm/version.hpp)
configure_file(src/realm/version_numbers.hpp.in src/realm/version_numbers.hpp)

set(DEPRECATED_CONFIG_FILE "${RealmCore_SOURCE_DIR}/src/realm/util/config.h")
if(EXISTS "${DEPRECATED_CONFIG_FILE}")
Expand Down
46 changes: 46 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// swift-tools-version:5.0

import PackageDescription
import Foundation

let versionStr = "5.22.0"
let versionPieces = versionStr.split(separator: "-")
let versionCompontents = versionPieces[0].split(separator: ".")
let versionExtra = versionPieces.count > 1 ? versionPieces[1] : ""

let package = Package(
name: "RealmCore",
products: [
.library(
name: "RealmCore",
targets: ["RealmCore"]),
],
targets: [
.target(
name: "RealmCore",
path: "src",
exclude: [
"realm/tools",
"realm/parser",
"realm/metrics",
"realm/exec",
"win32",
"external"
],
publicHeadersPath: ".",
cxxSettings: [
.headerSearchPath("src"),
.define("REALM_NO_CONFIG"),
.define("REALM_INSTALL_LIBEXECDIR", to: ""),
.define("REALM_ENABLE_ASSERTIONS", to: "1"),
.define("REALM_ENABLE_ENCRYPTION", to: "1"),

.define("REALM_VERSION_MAJOR", to: String(versionCompontents[0])),
.define("REALM_VERSION_MINOR", to: String(versionCompontents[1])),
.define("REALM_VERSION_PATCH", to: String(versionCompontents[2])),
.define("REALM_VERSION_EXTRA", to: "\"\(versionExtra)\""),
.define("REALM_VERSION_STRING", to: "\"\(versionStr)\""),
]),
],
cxxLanguageStandard: .cxx14
)
3 changes: 2 additions & 1 deletion src/realm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ set(REALM_INSTALL_GENERAL_HEADERS
timestamp.hpp
unicode.hpp
utilities.hpp
version.hpp
version_id.hpp
views.hpp
) # REALM_INSTALL_GENERAL_HEADERS
Expand Down Expand Up @@ -368,7 +369,7 @@ install(FILES ${REALM_OTHER_UTIL_HEADERS}
install(FILES ${REALM_METRICS_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/realm/metrics
COMPONENT devel)
install(FILES ${PROJECT_BINARY_DIR}/src/realm/version.hpp
install(FILES ${PROJECT_BINARY_DIR}/src/realm/version_numbers.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/realm
COMPONENT devel)
install(FILES ${PROJECT_BINARY_DIR}/src/realm/util/config.h
Expand Down
2 changes: 2 additions & 0 deletions src/realm/util/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
#define NOMINMAX
#endif

#ifndef REALM_NO_CONFIG
#include <realm/util/config.h>
#endif

/* The maximum number of elements in a B+-tree node. Applies to inner nodes and
* to leaves. The minimum allowable value is 2.
Expand Down
10 changes: 3 additions & 7 deletions src/realm/version.hpp.in → src/realm/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@

#include <string>

// Do not use `cmakedefine` here, as certain versions can be 0, which CMake
// interprets as being undefined.
#define REALM_VERSION_MAJOR @CONFIG_VERSION_MAJOR@
#define REALM_VERSION_MINOR @CONFIG_VERSION_MINOR@
#define REALM_VERSION_PATCH @CONFIG_VERSION_PATCH@
#define REALM_VERSION_EXTRA "@CONFIG_VERSION_TWEAK@"
#define REALM_VERSION_STRING "@CONFIG_VERSION@"
#ifndef REALM_VERSION_MAJOR
#include <realm/version_numbers.hpp>
#endif

#define REALM_PRODUCT_NAME "realm-core"
#define REALM_VER_CHUNK "[" REALM_PRODUCT_NAME "-" REALM_VERSION_STRING "]"
Expand Down
30 changes: 30 additions & 0 deletions src/realm/version_numbers.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*************************************************************************
*
* Copyright 2016 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**************************************************************************/

#ifndef REALM_VERSION_NUMBERS_HPP
#define REALM_VERSION_NUMBERS_HPP

// Do not use `cmakedefine` here, as certain versions can be 0, which CMake
// interprets as being undefined.
#define REALM_VERSION_MAJOR @CONFIG_VERSION_MAJOR@
#define REALM_VERSION_MINOR @CONFIG_VERSION_MINOR@
#define REALM_VERSION_PATCH @CONFIG_VERSION_PATCH@
#define REALM_VERSION_EXTRA "@CONFIG_VERSION_TWEAK@"
#define REALM_VERSION_STRING "@CONFIG_VERSION@"

#endif // REALM_VERSION_NUMBERS_HPP
4 changes: 4 additions & 0 deletions tools/release-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ git checkout -b prepare-$realm_version
sed -i.bak -e "s/^VERSION.*/VERSION=${realm_version}/" "${project_dir}/dependencies.list"
rm "${project_dir}/dependencies.list.bak" || exit 1

# update Package.swift
sed -i.bak -e "s/^let versionStr =.*/let versionStr = \"${realm_version}\"/" "${project_dir}/Package.swift"
rm "${project_dir}/Package.swift.bak" || exit 1

RELEASE_HEADER="# $realm_version Release notes" || exit 1
sed -i.bak -e "1s/.*/$RELEASE_HEADER/" "${project_dir}/CHANGELOG.md" || exit 1
rm "${project_dir}/CHANGELOG.md.bak" || exit 1
Expand Down